From 3547bb9db1743274c3d32f2fa396c573b576f691 Mon Sep 17 00:00:00 2001 From: Nikos Triantafyllou Date: Thu, 25 Apr 2024 12:40:57 +0300 Subject: [PATCH] bug fix with multiple sesion generation --- package.json | 2 +- routes/codeFlowJwtRoutes.js | 39 ++++++++++++++++++++--------------- routes/codeFlowSdJwtRoutes.js | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index c40c9ea..d965b35 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "SERVER_URL=https://e291-2a02-587-870e-d900-e57-8841-12f9-5aca.ngrok-free.app node server.js" + "dev": "SERVER_URL=https://a8a3-2a02-587-870e-d900-4edf-d4c0-8e40-c64b.ngrok-free.app node server.js" }, "author": "", "license": "ISC", diff --git a/routes/codeFlowJwtRoutes.js b/routes/codeFlowJwtRoutes.js index e1e91c2..d80596f 100644 --- a/routes/codeFlowJwtRoutes.js +++ b/routes/codeFlowJwtRoutes.js @@ -22,7 +22,7 @@ codeFlowRouter.get(["/offer-code"], async (req, res) => { const codeSessions = getAuthCodeSessions(); if (codeSessions.sessions.indexOf(uuid) < 0) { codeSessions.sessions.push(uuid); - codeSessions.results.push({ sessionId: uuid, status: "pending" }); + // codeSessions.results.push({ sessionId: uuid, status: "pending" }); } // console.log("active sessions"); @@ -99,22 +99,27 @@ codeFlowRouter.get("/authorize", async (req, res) => { // If validations pass, redirect with a 302 Found response const authorizationCode = null; //"SplxlOBeZQQYbYS6WxSbIA"; - const codeSessions = getAuthCodeSessions(); - codeSessions.requests.push({ - challenge: codeChallenge, - method: codeChallengeMethod, - sessionId: authorizationCode, - issuerState: issuerState, - state: state, - }); - codeSessions.results.push({ - sessionId: authorizationCode, - issuerState: issuerState, - state: state, - status: "pending", - }); - codeSessions.walletSessions.push(state); // push state as send by wallet - codeSessions.sessions.push(issuerState); + if (codeSessions.sessions.indexOf(issuerState)) { + const codeSessions = getAuthCodeSessions(); + codeSessions.requests.push({ + challenge: codeChallenge, + method: codeChallengeMethod, + sessionId: authorizationCode, + issuerState: issuerState, + state: state, + }); + codeSessions.results.push({ + sessionId: authorizationCode, + issuerState: issuerState, + state: state, + status: "pending", + }); + codeSessions.walletSessions.push(state); // push state as send by wallet + }else{ + console.log("ITB session not found") + } + + // codeSessions.sessions.push(issuerState); // for normal response not requesting VP from wallet //const redirectUrl = `${redirectUri}?code=${authorizationCode}&state=${state}`; diff --git a/routes/codeFlowSdJwtRoutes.js b/routes/codeFlowSdJwtRoutes.js index c3bfa6f..6c3b7e7 100644 --- a/routes/codeFlowSdJwtRoutes.js +++ b/routes/codeFlowSdJwtRoutes.js @@ -19,7 +19,7 @@ codeFlowRouterSDJWT.get(["/offer-code-sd-jwt"], async (req, res) => { const codeSessions = getAuthCodeSessions(); if (codeSessions.sessions.indexOf(uuid) < 0) { codeSessions.sessions.push(uuid); - codeSessions.results.push({ sessionId: uuid, status: "pending" }); + // codeSessions.results.push({ sessionId: uuid, status: "pending" }); } let credentialOffer = `openid-credential-offer://?credential_offer_uri=${serverURL}/credential-offer-code-sd-jwt/${uuid}`;