How to use the jwk-to-pem function in jwk-to-pem

To help you get started, we’ve selected a few jwk-to-pem 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 portier / portier-node / src / client.ts View on Github external
}

  // Get the public key.
  if (!Array.isArray(keysDoc.keys)) {
    throw Error("Keys document incorrectly formatted");
  }
  const key = keysDoc.keys.find((key: any) => {
    return key && key.alg === "RS256" && key.kid === header.kid;
  });
  if (!key) {
    throw Error("Cannot find the public key used to sign the token");
  }

  // Verify the signature.
  const signingInput = `${rawHeader}.${rawPayload}`;
  if (!rs256.verify(signingInput, signature, jwkToPem(key))) {
    throw Error("Token signature did not validate");
  }

  // Decode the payload.
  let payload;
  try {
    payload = JSON.parse(Buffer.from(rawPayload, "base64").toString());
    if (!payload || typeof payload !== "object") {
      throw Error("not an object");
    }
  } catch (err) {
    throw Error(`Invalid token payload: ${err.message || err}`);
  }

  // Verify claims made in the token.
  const now = Date.now();
github webiny / webiny-js / packages / api-plugin-security-cognito / src / index.js View on Github external
async userFromToken({ idToken, SecurityUser }) {
                const jwks = await getJWKs();
                const { header } = jwt.decode(idToken, { complete: true });
                const jwk = jwks.find(key => key.kid === header.kid);

                const token = await verify(idToken, jwkToPem(jwk));
                if (token.token_use !== "id") {
                    const error = new Error("idToken is invalid!");
                    throw Object.assign(error, {
                        code: "SECURITY_COGNITO_INVALID_TOKEN"
                    });
                }

                const user = await SecurityUser.findOne({ query: { email: token.email } });

                if (!user) {
                    return null;
                }

                if (attrKeys.some(attr => token.hasOwnProperty(attr))) {
                    attrKeys.forEach(attr => {
                        user[updateAttributes[attr]] = token[attr];
github jkettmann / universal-react-relay-starter-kit / server / graphql / auth / verifyToken.js View on Github external
const pems = jwkSet.keys.reduce((tmpPems, key) => {
  const pem = jwkToPem({
    kty: key.kty,
    n: key.n,
    e: key.e,
  })
  return { ...tmpPems, [key.kid]: pem }
}, {})

jwk-to-pem

Convert a JSON Web Key to a PEM

Apache-2.0
Latest version published 27 days ago

Package Health Score

77 / 100
Full package analysis

Popular jwk-to-pem functions