Skip to content

Commit

Permalink
pre-auth flow for jwt_vc
Browse files Browse the repository at this point in the history
  • Loading branch information
endimion committed Apr 26, 2024
1 parent e756a4d commit 37333d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 44 additions & 2 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 37333d0

Please sign in to comment.