Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parse: false,
algorithms: options.algorithm ? [options.algorithm] : undefined,
};
let payload;
let header;
try {
({ protected: header, payload } = JWS.verify(jwt, keyOrStore, opts));
} catch (err) {
if (!isKeyStore(keyOrStore) || typeof keyOrStore.fresh !== 'function' || keyOrStore.fresh()) {
throw err;
}
await keyOrStore.refresh();
({ protected: header, payload } = JWS.verify(jwt, keyOrStore, opts));
}
payload = JSON.parse(payload);
this.assertPayload(payload, options);
return { payload, header };
}
static async verify(jwt, keyOrStore, options = {}) {
const opts = {
complete: true,
parse: false,
algorithms: options.algorithm ? [options.algorithm] : undefined,
};
let payload;
let header;
try {
({ protected: header, payload } = JWS.verify(jwt, keyOrStore, opts));
} catch (err) {
if (!isKeyStore(keyOrStore) || typeof keyOrStore.fresh !== 'function' || keyOrStore.fresh()) {
throw err;
}
await keyOrStore.refresh();
({ protected: header, payload } = JWS.verify(jwt, keyOrStore, opts));
}
payload = JSON.parse(payload);
this.assertPayload(payload, options);
return { payload, header };
}