jwt/unsecured.UnsecuredJWT
The UnsecuredJWT class is a utility for dealing with { "alg": "none" }
Unsecured JWTs.
example
ESM import
import { UnsecuredJWT } from 'jose/jwt/unsecured'
example
CJS import
const { UnsecuredJWT } = require('jose/jwt/unsecured')
example
Encoding
const unsecuredJwt = new UnsecuredJWT({ 'urn:example:claim': true })
.setIssuedAt()
.setIssuer('urn:example:issuer')
.setAudience('urn:example:audience')
.setExpirationTime('2h')
.encode()
console.log(unsecuredJwt)
example
Decoding
const payload = new UnsecuredJWT.decode(jwt, {
issuer: 'urn:example:issuer',
audience: 'urn:example:audience'
})
console.log(payload)
-
ProduceJWT
↳
UnsecuredJWT
• new UnsecuredJWT(payload
)
Name | Type | Description |
---|---|---|
payload |
JWTPayload |
The JWT Claims Set object. |
ProduceJWT.constructor
▸ encode(): string
Encodes the Unsecured JWT.
string
▸ setAudience(audience
): UnsecuredJWT
Set "aud" (Audience) Claim.
Name | Type | Description |
---|---|---|
audience |
string | string [] |
"aud" (Audience) Claim value to set on the JWT Claims Set. |
ProduceJWT.setAudience
▸ setExpirationTime(input
): UnsecuredJWT
Set "exp" (Expiration Time) Claim.
Name | Type | Description |
---|---|---|
input |
string | number |
"exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. |
ProduceJWT.setExpirationTime
▸ setIssuedAt(input?
): UnsecuredJWT
Set "iat" (Issued At) Claim.
Name | Type | Description |
---|---|---|
input? |
number |
"iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp. |
ProduceJWT.setIssuedAt
▸ setIssuer(issuer
): UnsecuredJWT
Set "iss" (Issuer) Claim.
Name | Type | Description |
---|---|---|
issuer |
string |
"Issuer" Claim value to set on the JWT Claims Set. |
ProduceJWT.setIssuer
▸ setJti(jwtId
): UnsecuredJWT
Set "jti" (JWT ID) Claim.
Name | Type | Description |
---|---|---|
jwtId |
string |
"jti" (JWT ID) Claim value to set on the JWT Claims Set. |
ProduceJWT.setJti
▸ setNotBefore(input
): UnsecuredJWT
Set "nbf" (Not Before) Claim.
Name | Type | Description |
---|---|---|
input |
string | number |
"nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed that is used as a value, when string is passed it is resolved to a time span and added to the current timestamp. |
ProduceJWT.setNotBefore
▸ setSubject(subject
): UnsecuredJWT
Set "sub" (Subject) Claim.
Name | Type | Description |
---|---|---|
subject |
string |
"sub" (Subject) Claim value to set on the JWT Claims Set. |
ProduceJWT.setSubject
▸ Static
decode(jwt
, options?
): UnsecuredResult
Decodes an unsecured JWT.
Name | Type | Description |
---|---|---|
jwt |
string |
Unsecured JWT to decode the payload of. |
options? |
JWTClaimVerificationOptions |
JWT Claims Set validation options. |