From 37333d0aab1db81974ed9676f35daef0921cccf5 Mon Sep 17 00:00:00 2001 From: Nikos Triantafyllou Date: Fri, 26 Apr 2024 13:50:16 +0300 Subject: [PATCH] pre-auth flow for jwt_vc --- package.json | 2 +- routes/routes.js | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d965b35..3100c8e 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://a8a3-2a02-587-870e-d900-4edf-d4c0-8e40-c64b.ngrok-free.app node server.js" + "dev": "SERVER_URL=https://0a15-2a02-587-870e-d900-ed80-93f1-689f-839a.ngrok-free.app node server.js" }, "author": "", "license": "ISC", diff --git a/routes/routes.js b/routes/routes.js index 2517591..8a0bd81 100644 --- a/routes/routes.js +++ b/routes/routes.js @@ -39,7 +39,7 @@ const publicKeyPem = fs.readFileSync("./public-key.pem", "utf-8"); console.log("privateKey"); console.log(privateKey); -///pre-auth flow +///pre-auth flow sd-jwt router.get(["/offer"], async (req, res) => { const uuid = req.query.sessionId ? req.query.sessionId : uuidv4(); const preSessions = getPreCodeSessions(); @@ -67,7 +67,7 @@ router.get(["/offer"], async (req, res) => { }); }); -//pre-auth flow request +//pre-auth flow request sd-jwt router.get(["/credential-offer/:id"], (req, res) => { res.json({ credential_issuer: serverURL, @@ -81,6 +81,48 @@ router.get(["/credential-offer/:id"], (req, res) => { }); }); +// *************** +///pre-auth flow jwt_ve +router.get(["/pre-offer-jwt"], async (req, res) => { + const uuid = req.query.sessionId ? req.query.sessionId : uuidv4(); + const preSessions = getPreCodeSessions(); + if (preSessions.sessions.indexOf(uuid) < 0) { + preSessions.sessions.push(uuid); + preSessions.results.push({ sessionId: uuid, status: "pending" }); + } + let credentialOffer = `openid-credential-offer://?credential_offer_uri=${serverURL}/credential-offer-pre-jwt/${uuid}`; //OfferUUID + let code = qr.image(credentialOffer, { + type: "png", + ec_level: "H", + size: 10, + margin: 10, + }); + let mediaType = "PNG"; + let encodedQR = imageDataURI.encode(await streamToBuffer(code), mediaType); + res.json({ + qr: encodedQR, + deepLink: credentialOffer, + sessionId: uuid, + }); +}); + +//pre-auth flow request sd-jwt +router.get(["/credential-offer-pre-jwt/:id"], (req, res) => { + res.json({ + credential_issuer: serverURL, + credentials: ["VerifiablePortableDocumentA2"], + grants: { + "urn:ietf:params:oauth:grant-type:pre-authorized_code": { + "pre-authorized_code": req.params.id, + user_pin_required: true, + }, + }, + }); +}); + + + + router.post("/token_endpoint", async (req, res) => { //pre-auth code flow const grantType = req.body.grant_type;