@@ -37,48 +37,48 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
37
37
const patient_doc = await patients . get ( doc . email ) ;
38
38
console . log ( doc ) ;
39
39
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')
67
50
// }
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')
76
53
// }
77
- // await patients.insert(patient_doc);
78
54
// 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'});
81
58
// }
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
+ }
82
82
} else {
83
83
res . status ( 400 ) . json ( { error : 'invalid_request' } ) ;
84
84
}
0 commit comments