Back to Jose

Function: EmbeddedJWK()

docs/jwk/embedded/functions/EmbeddedJWK.md

6.2.122.1 KB
Original Source

Function: EmbeddedJWK()

šŸ’— Help the project

Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.

ā–ø EmbeddedJWK(protectedHeader?, token?): Promise<CryptoKey>

Resolves a verification key from an embedded "jwk" (JSON Web Key) Header Parameter. This key resolver opts JWS and JWT verification into trusting a public key supplied by the token. Use the verification function's algorithms option to restrict accepted algorithms.

This function is exported (as a named export) from the main 'jose' module entry point as well as from its subpath export 'jose/jwk/embedded'.

Parameters

ParameterTypeDescription
protectedHeader?JWSHeaderParametersJWS Protected Header.
token?FlattenedJWSInputThe consumed JWS token.

Returns

Promise<CryptoKey>

The public key from the JWS "jwk" (JSON Web Key) Header Parameter.

Example

js
const jwt =
  'eyJqd2siOnsiY3J2IjoiUC0yNTYiLCJ4IjoiVU05ZzVuS25aWFlvdldBbE03NmNMejl2VG96UmpfX0NIVV9kT2wtZ09vRSIsInkiOiJkczhhZVF3MWwyY0RDQTdiQ2tPTnZ3REtwWEFidFhqdnFDbGVZSDhXc19VIiwia3R5IjoiRUMifSwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSIsImlhdCI6MTYwNDU4MDc5NH0.60boak3_dErnW47ZPty1C0nrjeVq86EN_eK0GOq6K8w2OA0thKoBxFK4j-NuU9yZ_A9UKGxPT_G87DladBaV9g'

const { payload, protectedHeader } = await jose.jwtVerify(jwt, jose.EmbeddedJWK, {
  issuer: 'urn:example:issuer',
  audience: 'urn:example:audience',
})

console.log(protectedHeader)
console.log(payload)