added more info on token parse error

This commit is contained in:
Marco Lettere 2021-10-22 12:45:21 +02:00
parent 66a86dfe1a
commit 571a988be9
1 changed files with 12 additions and 2 deletions

View File

@ -129,7 +129,12 @@ function verifyToken(context){
return context.request.subrequest("/jwt_verify_request", options)
.then(reply=>{
if (reply.status === 200) {
var response = JSON.parse(reply.responseBody);
var response = null
try{
response = JSON.parse(reply.responseBody);
} catch(error){
throw new Error("Unable to parse response json from token request: " + reply.responseBody)
}
if (response.active === true) {
return response
} else {
@ -153,7 +158,12 @@ function requestToken(context){
return context.request.subrequest("/jwt_request", options)
.then(reply=>{
if (reply.status === 200) {
var response = JSON.parse(reply.responseBody);
var response = null
try{
response = JSON.parse(reply.responseBody);
} catch(error){
throw new Error("Unable to parse response json from token request: " + reply.responseBody)
}
context.authn.token = response.access_token
context.authn.verified_token =
JSON.parse(Buffer.from(context.authn.token.split('.')[1], 'base64url').toString())