@types/jsonwebtoken

  • Version 8.5.5
  • Published
  • 13.5 kB
  • 1 dependency
  • MIT license

Install

npm i @types/jsonwebtoken
yarn add @types/jsonwebtoken
pnpm add @types/jsonwebtoken

Overview

TypeScript definitions for jsonwebtoken

Index

Functions

function decode

decode: {
(token: string, options: DecodeOptions & { complete: true }): null | Jwt;
(token: string, options: DecodeOptions & { json: true }): JwtPayload;
(token: string, options?: DecodeOptions): string | JwtPayload;
};
  • Returns the decoded payload without verifying if the signature is valid. token - JWT string to decode [options] - Options for decoding returns - The decoded Token

function sign

sign: {
(
payload: string | Buffer | object,
secretOrPrivateKey: Secret,
options?: SignOptions
): string;
(payload: any, secretOrPrivateKey: any, callback: SignCallback): void;
(
payload: any,
secretOrPrivateKey: any,
options: SignOptions,
callback: SignCallback
): void;
};
  • Synchronously sign the given payload into a JSON Web Token string payload - Payload to sign, could be an literal, buffer or string secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA. [options] - Options for the signature returns - The JSON Web Token string

  • Sign the given payload into a JSON Web Token string payload - Payload to sign, could be an literal, buffer or string secretOrPrivateKey - Either the secret for HMAC algorithms, or the PEM encoded private key for RSA and ECDSA. [options] - Options for the signature callback - Callback to get the encoded token on

function verify

verify: {
(
token: string,
secretOrPublicKey: Secret,
options: VerifyOptions & { complete: true }
): Jwt | string;
(token: string, secretOrPublicKey: any, options?: VerifyOptions):
| string
| JwtPayload;
(
token: string,
secretOrPublicKey: any,
callback?: VerifyCallback<JwtPayload>
): void;
(
token: string,
secretOrPublicKey: any,
options?: VerifyOptions & { complete: true },
callback?: VerifyCallback<Jwt>
): void;
(
token: string,
secretOrPublicKey: any,
options?: VerifyOptions,
callback?: VerifyCallback<JwtPayload>
): void;
};
  • Synchronously verify given token using a secret or a public key to get a decoded token token - JWT string to verify secretOrPublicKey - Either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA. [options] - Options for the verification returns - The decoded token.

  • Asynchronously verify given token using a secret or a public key to get a decoded token token - JWT string to verify secretOrPublicKey - A string or buffer containing either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA. If jwt.verify is called asynchronous, secretOrPublicKey can be a function that should fetch the secret or public key [options] - Options for the verification callback - Callback to get the decoded token on

Classes

class JsonWebTokenError

class JsonWebTokenError extends Error {}

    constructor

    constructor(message: string, error?: Error);

      property inner

      inner: Error;

        class NotBeforeError

        class NotBeforeError extends JsonWebTokenError {}
        • Thrown if current time is before the nbf claim.

        constructor

        constructor(message: string, date: Date);

          property date

          date: Date;

            class TokenExpiredError

            class TokenExpiredError extends JsonWebTokenError {}

              constructor

              constructor(message: string, expiredAt: Date);

                property expiredAt

                expiredAt: Date;

                  Interfaces

                  interface DecodeOptions

                  interface DecodeOptions {}

                    property complete

                    complete?: boolean | undefined;

                      property json

                      json?: boolean | undefined;

                        interface Jwt

                        interface Jwt {}

                          property header

                          header: JwtHeader;

                            property payload

                            payload: JwtPayload;

                              property signature

                              signature: string;

                                interface JwtHeader

                                interface JwtHeader {}

                                  property 'x5t#S256'

                                  'x5t#S256'?: string | undefined;

                                    property alg

                                    alg: string | Algorithm;

                                      property crit

                                      crit?: Array<string | Exclude<keyof JwtHeader, 'crit'>> | undefined;

                                        property cty

                                        cty?: string | undefined;

                                          property jku

                                          jku?: string | undefined;

                                            property kid

                                            kid?: string | undefined;

                                              property typ

                                              typ?: string | undefined;

                                                property x5c

                                                x5c?: string | string[] | undefined;

                                                  property x5t

                                                  x5t?: string | undefined;

                                                    property x5u

                                                    x5u?: string | string[] | undefined;

                                                      interface JwtPayload

                                                      interface JwtPayload {}

                                                        property aud

                                                        aud?: string | string[] | undefined;

                                                          property exp

                                                          exp?: number | undefined;

                                                            property iat

                                                            iat?: number | undefined;

                                                              property iss

                                                              iss?: string | undefined;

                                                                property jti

                                                                jti?: string | undefined;

                                                                  property nbf

                                                                  nbf?: number | undefined;

                                                                    property sub

                                                                    sub?: string | undefined;

                                                                      index signature

                                                                      [key: string]: any;

                                                                        interface SignOptions

                                                                        interface SignOptions {}

                                                                          property algorithm

                                                                          algorithm?: Algorithm | undefined;
                                                                          • Signature algorithm. Could be one of these values : - HS256: HMAC using SHA-256 hash algorithm (default) - HS384: HMAC using SHA-384 hash algorithm - HS512: HMAC using SHA-512 hash algorithm - RS256: RSASSA using SHA-256 hash algorithm - RS384: RSASSA using SHA-384 hash algorithm - RS512: RSASSA using SHA-512 hash algorithm - ES256: ECDSA using P-256 curve and SHA-256 hash algorithm - ES384: ECDSA using P-384 curve and SHA-384 hash algorithm - ES512: ECDSA using P-521 curve and SHA-512 hash algorithm - none: No digital signature or MAC value included

                                                                          property audience

                                                                          audience?: string | string[] | undefined;

                                                                            property encoding

                                                                            encoding?: string | undefined;

                                                                              property expiresIn

                                                                              expiresIn?: string | number | undefined;
                                                                              • expressed in seconds or a string describing a time span [zeit/ms](https://github.com/zeit/ms.js). Eg: 60, "2 days", "10h", "7d"

                                                                              property header

                                                                              header?: JwtHeader | undefined;

                                                                                property issuer

                                                                                issuer?: string | undefined;

                                                                                  property jwtid

                                                                                  jwtid?: string | undefined;

                                                                                    property keyid

                                                                                    keyid?: string | undefined;

                                                                                      property mutatePayload

                                                                                      mutatePayload?: boolean | undefined;

                                                                                        property notBefore

                                                                                        notBefore?: string | number | undefined;
                                                                                        • expressed in seconds or a string describing a time span [zeit/ms](https://github.com/zeit/ms.js). Eg: 60, "2 days", "10h", "7d"

                                                                                        property noTimestamp

                                                                                        noTimestamp?: boolean | undefined;

                                                                                          property subject

                                                                                          subject?: string | undefined;

                                                                                            interface VerifyOptions

                                                                                            interface VerifyOptions {}

                                                                                              property algorithms

                                                                                              algorithms?: Algorithm[] | undefined;

                                                                                                property audience

                                                                                                audience?: string | RegExp | Array<string | RegExp> | undefined;

                                                                                                  property clockTimestamp

                                                                                                  clockTimestamp?: number | undefined;

                                                                                                    property clockTolerance

                                                                                                    clockTolerance?: number | undefined;

                                                                                                      property complete

                                                                                                      complete?: boolean | undefined;
                                                                                                      • return an object with the decoded { payload, header, signature } instead of only the usual content of the payload.

                                                                                                      property ignoreExpiration

                                                                                                      ignoreExpiration?: boolean | undefined;

                                                                                                        property ignoreNotBefore

                                                                                                        ignoreNotBefore?: boolean | undefined;

                                                                                                          property issuer

                                                                                                          issuer?: string | string[] | undefined;

                                                                                                            property jwtid

                                                                                                            jwtid?: string | undefined;

                                                                                                              property maxAge

                                                                                                              maxAge?: string | undefined;
                                                                                                              • Deprecated

                                                                                                                Max age of token

                                                                                                              property nonce

                                                                                                              nonce?: string | undefined;
                                                                                                              • If you want to check nonce claim, provide a string value here. It is used on Open ID for the ID Tokens. ([Open ID implementation notes](https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes))

                                                                                                              property subject

                                                                                                              subject?: string | undefined;

                                                                                                                Type Aliases

                                                                                                                type Algorithm

                                                                                                                type Algorithm =
                                                                                                                | 'HS256'
                                                                                                                | 'HS384'
                                                                                                                | 'HS512'
                                                                                                                | 'RS256'
                                                                                                                | 'RS384'
                                                                                                                | 'RS512'
                                                                                                                | 'ES256'
                                                                                                                | 'ES384'
                                                                                                                | 'ES512'
                                                                                                                | 'PS256'
                                                                                                                | 'PS384'
                                                                                                                | 'PS512'
                                                                                                                | 'none';

                                                                                                                  type GetPublicKeyOrSecret

                                                                                                                  type GetPublicKeyOrSecret = (
                                                                                                                  header: JwtHeader,
                                                                                                                  callback: SigningKeyCallback
                                                                                                                  ) => void;

                                                                                                                    type Secret

                                                                                                                    type Secret = string | Buffer | { key: string | Buffer; passphrase: string };

                                                                                                                      type SignCallback

                                                                                                                      type SignCallback = (err: Error | null, encoded: string | undefined) => void;

                                                                                                                        type SigningKeyCallback

                                                                                                                        type SigningKeyCallback = (err: any, signingKey?: Secret) => void;

                                                                                                                          type VerifyCallback

                                                                                                                          type VerifyCallback<T = JwtPayload> = (
                                                                                                                          err: VerifyErrors | null,
                                                                                                                          decoded: T | undefined
                                                                                                                          ) => void;

                                                                                                                            type VerifyErrors

                                                                                                                            type VerifyErrors = JsonWebTokenError | NotBeforeError | TokenExpiredError;

                                                                                                                              Package Files (1)

                                                                                                                              Dependencies (1)

                                                                                                                              Dev Dependencies (0)

                                                                                                                              No dev dependencies.

                                                                                                                              Peer Dependencies (0)

                                                                                                                              No peer dependencies.

                                                                                                                              Badge

                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/jsonwebtoken.

                                                                                                                              • Markdown
                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/jsonwebtoken)
                                                                                                                              • HTML
                                                                                                                                <a href="https://www.jsdocs.io/package/@types/jsonwebtoken"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>