Skip to content

Latest commit

 

History

History
302 lines (175 loc) · 6.53 KB

jwt_unsecured.unsecuredjwt.md

File metadata and controls

302 lines (175 loc) · 6.53 KB

Class: UnsecuredJWT

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)

Hierarchy

  • ProduceJWT

    UnsecuredJWT

Table of contents

Constructors

Methods

Constructors

constructor

new UnsecuredJWT(payload)

Parameters

Name Type Description
payload JWTPayload The JWT Claims Set object.

Inherited from

ProduceJWT.constructor

Defined in

lib/jwt_producer.ts:10

Methods

encode

encode(): string

Encodes the Unsecured JWT.

Returns

string

Defined in

jwt/unsecured.ts:54


setAudience

setAudience(audience): UnsecuredJWT

Set "aud" (Audience) Claim.

Parameters

Name Type Description
audience string | string[] "aud" (Audience) Claim value to set on the JWT Claims Set.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setAudience

Defined in

lib/jwt_producer.ts:47


setExpirationTime

setExpirationTime(input): UnsecuredJWT

Set "exp" (Expiration Time) Claim.

Parameters

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.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setExpirationTime

Defined in

lib/jwt_producer.ts:85


setIssuedAt

setIssuedAt(input?): UnsecuredJWT

Set "iat" (Issued At) Claim.

Parameters

Name Type Description
input? number "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current timestamp.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setIssuedAt

Defined in

lib/jwt_producer.ts:100


setIssuer

setIssuer(issuer): UnsecuredJWT

Set "iss" (Issuer) Claim.

Parameters

Name Type Description
issuer string "Issuer" Claim value to set on the JWT Claims Set.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setIssuer

Defined in

lib/jwt_producer.ts:27


setJti

setJti(jwtId): UnsecuredJWT

Set "jti" (JWT ID) Claim.

Parameters

Name Type Description
jwtId string "jti" (JWT ID) Claim value to set on the JWT Claims Set.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setJti

Defined in

lib/jwt_producer.ts:57


setNotBefore

setNotBefore(input): UnsecuredJWT

Set "nbf" (Not Before) Claim.

Parameters

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.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setNotBefore

Defined in

lib/jwt_producer.ts:69


setSubject

setSubject(subject): UnsecuredJWT

Set "sub" (Subject) Claim.

Parameters

Name Type Description
subject string "sub" (Subject) Claim value to set on the JWT Claims Set.

Returns

UnsecuredJWT

Inherited from

ProduceJWT.setSubject

Defined in

lib/jwt_producer.ts:37


decode

Static decode(jwt, options?): UnsecuredResult

Decodes an unsecured JWT.

Parameters

Name Type Description
jwt string Unsecured JWT to decode the payload of.
options? JWTClaimVerificationOptions JWT Claims Set validation options.

Returns

UnsecuredResult

Defined in

jwt/unsecured.ts:67