Skip to content

Commit

Permalink
feat: remove code challenge + add login hint
Browse files Browse the repository at this point in the history
  • Loading branch information
rdubigny committed Mar 14, 2024
1 parent 609f87f commit 6679d26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ MCP_SCOPES: "openid email profile organization"
LOGIN_HINT: ""
MCP_ID_TOKEN_SIGNED_RESPONSE_ALG: RS256
MCP_USERINFO_SIGNED_RESPONSE_ALG: ""
ACR_VALUES: ""
37 changes: 11 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ app.use(
cookieSession({
name: "mcp_session",
keys: ["key1", "key2"],
})
}),
);
app.use(morgan("combined"));

Expand Down Expand Up @@ -50,15 +50,15 @@ app.get("/", async (req, res, next) => {
app.post("/login", async (req, res, next) => {
try {
const client = await getMcpClient();
const code_verifier = generators.codeVerifier();
req.session.verifier = code_verifier;
const code_challenge = generators.codeChallenge(code_verifier);
const acr_values = process.env.ACR_VALUES
? process.env.ACR_VALUES.split(",")
: null;

const redirectUrl = client.authorizationUrl({
scope: process.env.MCP_SCOPES,
code_challenge,
code_challenge_method: "S256",
login_hint: process.env.LOGIN_HINT,
// claims: { id_token: { amr: { essential: true } } },
login_hint: process.env.LOGIN_HINT || null,
acr_values,
});

res.redirect(redirectUrl);
Expand All @@ -71,9 +71,7 @@ app.get(process.env.CALLBACK_URL, async (req, res, next) => {
try {
const client = await getMcpClient();
const params = client.callbackParams(req);
const tokenSet = await client.callback(redirectUri, params, {
code_verifier: req.session.verifier,
});
const tokenSet = await client.callback(redirectUri, params);

req.session.userinfo = await client.userinfo(tokenSet.access_token);
req.session.idtoken = tokenSet.claims();
Expand All @@ -88,14 +86,10 @@ app.get(process.env.CALLBACK_URL, async (req, res, next) => {
app.post("/select-organization", async (req, res, next) => {
try {
const client = await getMcpClient();
const code_verifier = generators.codeVerifier();
req.session.verifier = code_verifier;
const code_challenge = generators.codeChallenge(code_verifier);

const redirectUrl = client.authorizationUrl({
scope: process.env.MCP_SCOPES,
code_challenge,
code_challenge_method: "S256",
login_hint: process.env.LOGIN_HINT || null,
prompt: "select_organization",
});

Expand All @@ -108,14 +102,9 @@ app.post("/select-organization", async (req, res, next) => {
app.post("/update-userinfo", async (req, res, next) => {
try {
const client = await getMcpClient();
const code_verifier = generators.codeVerifier();
req.session.verifier = code_verifier;
const code_challenge = generators.codeChallenge(code_verifier);

const redirectUrl = client.authorizationUrl({
scope: process.env.MCP_SCOPES,
code_challenge,
code_challenge_method: "S256",
login_hint: process.env.LOGIN_HINT || null,
prompt: "update_userinfo",
});

Expand All @@ -142,15 +131,11 @@ app.post("/logout", async (req, res, next) => {
app.post("/force-login", async (req, res, next) => {
try {
const client = await getMcpClient();
const code_verifier = generators.codeVerifier();
req.session.verifier = code_verifier;
const code_challenge = generators.codeChallenge(code_verifier);

const redirectUrl = client.authorizationUrl({
scope: process.env.MCP_SCOPES,
claims: { id_token: { auth_time: { essential: true } } },
code_challenge,
code_challenge_method: "S256",
login_hint: process.env.LOGIN_HINT || null,
prompt: "login",
// alternatively, you can use the 'max_age: 0'
// if so, claims parameter is not necessary as auth_time will be returned
Expand Down
4 changes: 4 additions & 0 deletions package-lock.json

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

0 comments on commit 6679d26

Please sign in to comment.