How to use the jose.JWS.verify function in jose

To help you get started, we’ve selected a few jose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github panva / node-oidc-provider / lib / helpers / jwt.js View on Github external
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 };
  }
github panva / node-oidc-provider / lib / helpers / jwt.js View on Github external
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 };
  }

jose

JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes

MIT
Latest version published 13 days ago

Package Health Score

94 / 100
Full package analysis