mirror of
https://github.com/danbulant/jose
synced 2026-05-24 20:41:46 +00:00
1.9 KiB
1.9 KiB
Function: jwtVerify
▸ jwtVerify(jwt: string | Uint8Array, key: KeyLike | JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult>
Defined in src/jwt/verify.ts:67
Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the JWT Claims Set.
example
// ESM import
import jwtVerify from 'jose/jwt/verify'
example
// CJS import
const { default: jwtVerify } = require('jose/jwt/verify')
example
// usage
import parseJwk from 'jose/jwk/parse'
const jwt = 'eyJhbGciOiJFUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjA0MzE1MDc0LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.hx1nOfAT5LlXuzu8O-bhjXBGpklWDt2EsHw7-MDn49NrnwvVsstNhEnkW2ddauB7eSikFtUNeumLpFI9CWDBsg'
const publicKey = await parseJwk({
alg: 'ES256',
crv: 'P-256',
kty: 'EC',
x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo'
})
const { payload, protectedHeader } = await jwtVerify(jwt, publicKey, {
issuer: 'urn:example:issuer',
audience: 'urn:example:audience'
})
console.log(protectedHeader)
console.log(payload)
Parameters:
| Name | Type | Description |
|---|---|---|
jwt |
string | Uint8Array | JSON Web Token value (encoded as JWS). |
key |
KeyLike | JWTVerifyGetKey | Key, or a function resolving a key, to verify the JWT with. |
options? |
JWTVerifyOptions | JWT Decryption and JWT Claims Set validation options. |
Returns: Promise<JWTVerifyResult>