Skip to content

Commit

Permalink
replace cookie session package with express-session
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano committed Apr 4, 2024
1 parent 40d6666 commit 770dde4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 113 deletions.
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "dotenv/config";
import express from "express";
import { Issuer } from "openid-client";
import cookieSession from "cookie-session";
import session from "express-session";
import morgan from "morgan";
import * as crypto from "crypto";

Expand All @@ -13,9 +13,9 @@ const app = express();

app.set("view engine", "ejs");
app.use(
cookieSession({
session({
secret: process.env.SESSION_SECRET,
name: "mcp_session",
keys: ["key1", "key2"],
})
);
app.use(morgan("combined"));
Expand Down Expand Up @@ -120,17 +120,19 @@ app.get(process.env.CALLBACK_URL, async (req, res, next) => {
req.session.userinfo = await client.userinfo(tokenSet.access_token);
req.session.idtoken = tokenSet.claims();
req.session.id_token_hint = tokenSet.id_token;

req.session.oauth2token = tokenSet;
req.session.save()
res.redirect("/");
} catch (e) {
console.error(e)
next(e);
}
});

app.post("/logout", async (req, res, next) => {
try {
const id_token_hint = req.session.id_token_hint;
req.session = null;
req.session.destroy()
const client = await getMcpClient();
const redirectUrl = client.endSessionUrl({
post_logout_redirect_uri: `${origin}/`,
Expand Down
198 changes: 91 additions & 107 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"cookie-session": "^2.1.0",
"dotenv": "^16.4.5",
"ejs": "^3.1.9",
"express": "^4.18.3",
"express-session": "^1.18.0",
"morgan": "^1.10.0",
"openid-client": "^5.6.5"
},
Expand Down

0 comments on commit 770dde4

Please sign in to comment.