@@ -37,20 +37,24 @@ 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
- console . log ( req . body . vp_token ) ;
41
- const { payload } = decodeJWT ( req . body . vp_token ) ;
42
- const verifiedAuthResponse = await rp . verifyAuthorizationResponse ( payload , {
43
- correlationId : doc . _id ,
44
- audience : url . protocol + "//" + url . hostname + "/api/vp/vp_response" ,
45
- } )
46
- console . log ( verifiedAuthResponse )
47
- if ( objectPath . get ( verifiedAuthResponse , 'payload.state' ) === doc . vp_state ) {
48
- console . log ( 'state matches' )
40
+ const { payload } = decodeJWT ( req . body . id_token ) ;
41
+ try {
42
+ const verifiedAuthResponse = await rp . verifyAuthorizationResponse ( payload , {
43
+ correlationId : doc . _id ,
44
+ audience : url . protocol + "//" + url . hostname + "/api/vp/vp_response" ,
45
+ } )
46
+ console . log ( verifiedAuthResponse )
47
+ if ( objectPath . get ( verifiedAuthResponse , 'payload.state' ) === doc . vp_state ) {
48
+ console . log ( 'state matches' )
49
+ }
50
+ if ( objectPath . get ( verifiedAuthResponse , 'payload.nonce' ) === doc . vp_state ) {
51
+ console . log ( 'state matches' )
52
+ }
53
+ res . status ( 200 ) . json ( { message : 'OK' } ) ;
54
+ } catch ( e ) {
55
+ console . log ( e )
56
+ res . status ( 400 ) . json ( { error : 'invalid_request' } ) ;
49
57
}
50
- if ( objectPath . get ( verifiedAuthResponse , 'payload.nonce' ) === doc . vp_state ) {
51
- console . log ( 'state matches' )
52
- }
53
- res . status ( 200 ) . json ( { message : 'OK' } ) ;
54
58
// if (objectPath.has(payload, 'vp.verifiableCredential')) {
55
59
// const vc = jose.decodeJwt(objectPath.get(payload, 'vp.verifiableCredential.0'));
56
60
// if (objectPath.has(doc, 'vc')) {
0 commit comments