Skip to content

Commit 6db6e66

Browse files
committed
debug
1 parent 6f39384 commit 6db6e66

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

lib/rp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const resolver = getResolver('ethr');
107107
export const rp = RP.builder({ requestVersion: SupportedVersion.SIOPv2_ID1 })
108108
.withClientId(identifier.did)
109109
.withScope('openid')
110-
.withResponseType('id_token')
110+
.withResponseType('vp_token')
111111
.withResponseMode(ResponseMode.POST)
112112
.withAuthorizationEndpoint(url_auth)
113113
.withRedirectUri(url_res)

pages/api/vp/response.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,48 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
3737
const patient_doc = await patients.get(doc.email);
3838
console.log(doc);
3939
console.log(req.body);
40-
const { payload } = decodeJWT(req.body.id_token);
41-
try {
42-
const verifiedAuthResponse = await rp.verifyAuthorizationResponse(req.body.id_token, {
43-
correlationId: doc._id,
44-
state: req.body.state,
45-
audience: url.protocol + "//" + url.hostname + "/api/vp/vp_response",
46-
})
47-
console.log(verifiedAuthResponse)
48-
if (objectPath.get(verifiedAuthResponse, 'payload.state') === doc.vp_state) {
49-
console.log('state matches')
50-
}
51-
if (objectPath.get(verifiedAuthResponse, 'payload.nonce') === doc.vp_state) {
52-
console.log('state matches')
53-
}
54-
res.status(200).json({message: 'OK'});
55-
} catch (e) {
56-
console.log(e)
57-
res.status(400).json({error: 'invalid_request'});
58-
}
59-
// if (objectPath.has(payload, 'vp.verifiableCredential')) {
60-
// const vc = jose.decodeJwt(objectPath.get(payload, 'vp.verifiableCredential.0'));
61-
// if (objectPath.has(doc, 'vc')) {
62-
// const vc_arr = objectPath.get(doc, 'vc');
63-
// vc_arr.push(vc);
64-
// objectPath.set(doc, 'vc', vc_arr);
65-
// } else {
66-
// objectPath.set(doc, 'vc.0', vc);
40+
const { payload } = decodeJWT(req.body.vp_token);
41+
// try {
42+
// const verifiedAuthResponse = await rp.verifyAuthorizationResponse(req.body.id_token, {
43+
// correlationId: doc._id,
44+
// state: req.body.state,
45+
// audience: url.protocol + "//" + url.hostname + "/api/vp/vp_response",
46+
// })
47+
// console.log(verifiedAuthResponse)
48+
// if (objectPath.get(verifiedAuthResponse, 'payload.state') === doc.vp_state) {
49+
// console.log('state matches')
6750
// }
68-
// objectPath.set(doc, 'vp_status', 'complete');
69-
// await gnap.insert(doc);
70-
// if (objectPath.has(patient_doc, 'vc')) {
71-
// const vc_arr1 = objectPath.get(patient_doc, 'vc');
72-
// vc_arr1.push(vc);
73-
// objectPath.set(patient_doc, 'vc', vc_arr1);
74-
// } else {
75-
// objectPath.set(patient_doc, 'vc.0', vc);
51+
// if (objectPath.get(verifiedAuthResponse, 'payload.nonce') === doc.vp_state) {
52+
// console.log('state matches')
7653
// }
77-
// await patients.insert(patient_doc);
7854
// res.status(200).json({message: 'OK'});
79-
// } else {
80-
// res.status(400).json({error: 'invalid_token'});
55+
// } catch (e) {
56+
// console.log(e)
57+
// res.status(400).json({error: 'invalid_request'});
8158
// }
59+
if (objectPath.has(payload, 'vp.verifiableCredential')) {
60+
const vc = decodeJWT(objectPath.get(payload, 'vp.verifiableCredential.0'));
61+
if (objectPath.has(doc, 'vc')) {
62+
const vc_arr = objectPath.get(doc, 'vc');
63+
vc_arr.push(vc);
64+
objectPath.set(doc, 'vc', vc_arr);
65+
} else {
66+
objectPath.set(doc, 'vc.0', vc);
67+
}
68+
objectPath.set(doc, 'vp_status', 'complete');
69+
await gnap.insert(doc);
70+
if (objectPath.has(patient_doc, 'vc')) {
71+
const vc_arr1 = objectPath.get(patient_doc, 'vc');
72+
vc_arr1.push(vc);
73+
objectPath.set(patient_doc, 'vc', vc_arr1);
74+
} else {
75+
objectPath.set(patient_doc, 'vc.0', vc);
76+
}
77+
await patients.insert(patient_doc);
78+
res.status(200).json({message: 'OK'});
79+
} else {
80+
res.status(400).json({error: 'invalid_token'});
81+
}
8282
} else {
8383
res.status(400).json({error: 'invalid_request'});
8484
}

0 commit comments

Comments
 (0)