Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
shihjay2 committed Jan 23, 2025
1 parent 6f39384 commit 6db6e66
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/rp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const resolver = getResolver('ethr');
export const rp = RP.builder({ requestVersion: SupportedVersion.SIOPv2_ID1 })
.withClientId(identifier.did)
.withScope('openid')
.withResponseType('id_token')
.withResponseType('vp_token')
.withResponseMode(ResponseMode.POST)
.withAuthorizationEndpoint(url_auth)
.withRedirectUri(url_res)
Expand Down
76 changes: 38 additions & 38 deletions pages/api/vp/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,48 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const patient_doc = await patients.get(doc.email);
console.log(doc);
console.log(req.body);
const { payload } = decodeJWT(req.body.id_token);
try {
const verifiedAuthResponse = await rp.verifyAuthorizationResponse(req.body.id_token, {
correlationId: doc._id,
state: req.body.state,
audience: url.protocol + "//" + url.hostname + "/api/vp/vp_response",
})
console.log(verifiedAuthResponse)
if (objectPath.get(verifiedAuthResponse, 'payload.state') === doc.vp_state) {
console.log('state matches')
}
if (objectPath.get(verifiedAuthResponse, 'payload.nonce') === doc.vp_state) {
console.log('state matches')
}
res.status(200).json({message: 'OK'});
} catch (e) {
console.log(e)
res.status(400).json({error: 'invalid_request'});
}
// if (objectPath.has(payload, 'vp.verifiableCredential')) {
// const vc = jose.decodeJwt(objectPath.get(payload, 'vp.verifiableCredential.0'));
// if (objectPath.has(doc, 'vc')) {
// const vc_arr = objectPath.get(doc, 'vc');
// vc_arr.push(vc);
// objectPath.set(doc, 'vc', vc_arr);
// } else {
// objectPath.set(doc, 'vc.0', vc);
const { payload } = decodeJWT(req.body.vp_token);
// try {
// const verifiedAuthResponse = await rp.verifyAuthorizationResponse(req.body.id_token, {
// correlationId: doc._id,
// state: req.body.state,
// audience: url.protocol + "//" + url.hostname + "/api/vp/vp_response",
// })
// console.log(verifiedAuthResponse)
// if (objectPath.get(verifiedAuthResponse, 'payload.state') === doc.vp_state) {
// console.log('state matches')
// }
// objectPath.set(doc, 'vp_status', 'complete');
// await gnap.insert(doc);
// if (objectPath.has(patient_doc, 'vc')) {
// const vc_arr1 = objectPath.get(patient_doc, 'vc');
// vc_arr1.push(vc);
// objectPath.set(patient_doc, 'vc', vc_arr1);
// } else {
// objectPath.set(patient_doc, 'vc.0', vc);
// if (objectPath.get(verifiedAuthResponse, 'payload.nonce') === doc.vp_state) {
// console.log('state matches')
// }
// await patients.insert(patient_doc);
// res.status(200).json({message: 'OK'});
// } else {
// res.status(400).json({error: 'invalid_token'});
// } catch (e) {
// console.log(e)
// res.status(400).json({error: 'invalid_request'});
// }
if (objectPath.has(payload, 'vp.verifiableCredential')) {
const vc = decodeJWT(objectPath.get(payload, 'vp.verifiableCredential.0'));
if (objectPath.has(doc, 'vc')) {
const vc_arr = objectPath.get(doc, 'vc');
vc_arr.push(vc);
objectPath.set(doc, 'vc', vc_arr);
} else {
objectPath.set(doc, 'vc.0', vc);
}
objectPath.set(doc, 'vp_status', 'complete');
await gnap.insert(doc);
if (objectPath.has(patient_doc, 'vc')) {
const vc_arr1 = objectPath.get(patient_doc, 'vc');
vc_arr1.push(vc);
objectPath.set(patient_doc, 'vc', vc_arr1);
} else {
objectPath.set(patient_doc, 'vc.0', vc);
}
await patients.insert(patient_doc);
res.status(200).json({message: 'OK'});
} else {
res.status(400).json({error: 'invalid_token'});
}
} else {
res.status(400).json({error: 'invalid_request'});
}
Expand Down

0 comments on commit 6db6e66

Please sign in to comment.