verify.js 974 B

1234567891011121314151617181920
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.jwtVerify = void 0;
  4. const verify_js_1 = require("../jws/compact/verify.js");
  5. const jwt_claims_set_js_1 = require("../lib/jwt_claims_set.js");
  6. const errors_js_1 = require("../util/errors.js");
  7. async function jwtVerify(jwt, key, options) {
  8. var _a;
  9. const verified = await (0, verify_js_1.compactVerify)(jwt, key, options);
  10. if (((_a = verified.protectedHeader.crit) === null || _a === void 0 ? void 0 : _a.includes('b64')) && verified.protectedHeader.b64 === false) {
  11. throw new errors_js_1.JWTInvalid('JWTs MUST NOT use unencoded payload');
  12. }
  13. const payload = (0, jwt_claims_set_js_1.default)(verified.protectedHeader, verified.payload, options);
  14. const result = { payload, protectedHeader: verified.protectedHeader };
  15. if (typeof key === 'function') {
  16. return { ...result, key: verified.key };
  17. }
  18. return result;
  19. }
  20. exports.jwtVerify = jwtVerify;