@types/passport-jwt

  • Version 4.0.1
  • Published
  • 9.3 kB
  • 2 dependencies
  • MIT license

Install

npm i @types/passport-jwt
yarn add @types/passport-jwt
pnpm add @types/passport-jwt

Overview

TypeScript definitions for passport-jwt

Index

Classes

class Strategy

class Strategy extends PassportStrategy {}

    constructor

    constructor(opt: StrategyOptionsWithoutRequest, verify: VerifyCallback);
    • Strategy constructor

    constructor

    constructor(
    opt: StrategyOptionsWithRequest,
    verify: VerifyCallbackWithRequest<any>
    );
    • Strategy constructor

    property name

    name: string;

      Interfaces

      interface BaseStrategyOptions

      interface BaseStrategyOptions {}

        property algorithms

        algorithms?: Algorithm[] | undefined;
        • List of strings with the names of allowed algorithms (e.g., ["HS256", "HS384"]).

        property audience

        audience?: string | string[] | undefined;
        • If defined, the audience will be verified against this value.

        property ignoreExpiration

        ignoreExpiration?: boolean | undefined;
        • If true, do not validate the expiration of the token.

        property issuer

        issuer?: string | string[] | undefined;
        • If defined, the issuer will be verified against this value.

        property jsonWebTokenOptions

        jsonWebTokenOptions?: VerifyOptions | undefined;
        • Deprecated

          for backwards compatibility, still allowing you to pass audience / issuer / algorithms / ignoreExpiration on the options.

        property jwtFromRequest

        jwtFromRequest: JwtFromRequestFunction;
        • Function that accepts a request as the only parameter and returns either the JWT as a string or null. REQUIRED.

        interface JwtFromRequestFunction

        interface JwtFromRequestFunction<T = any> {}
        • Function that returns either the JWT as a string or null.

        call signature

        (req: T): string | null;

          interface SecretOrKeyProvider

          interface SecretOrKeyProvider<T = any> {}
          • Interface for providing the secret or key for verification.

          call signature

          (
          request: T,
          rawJwtToken: any,
          done: (err: any, secretOrKey?: string | Buffer) => void
          ): void;
          • Callback for secret or key provider.

            Parameter request

            The request object from your framework (e.g., Express.Request)

            Parameter rawJwtToken

            The raw JWT token string

            Parameter done

            A function with the signature function(err, secret)

          interface VerifiedCallback

          interface VerifiedCallback {}
          • Callback for the verified result.

          call signature

          (error: any, user?: unknown | false, info?: any): void;

            interface WithSecretOrKey

            interface WithSecretOrKey extends BaseStrategyOptions {}

              property secretOrKey

              secretOrKey: string | Buffer;

                interface WithSecretOrKeyProvider

                interface WithSecretOrKeyProvider extends BaseStrategyOptions {}

                  property secretOrKeyProvider

                  secretOrKeyProvider: SecretOrKeyProvider;

                    Type Aliases

                    type StrategyOptions

                    type StrategyOptions = StrategyOptionsWithRequest | StrategyOptionsWithoutRequest;
                    • Union type for all possible Strategy options.

                    type StrategyOptionsWithoutRequest

                    type StrategyOptionsWithoutRequest = StrategyOptionsWithSecret & {
                    /**
                    * If true, the verify callback will be called with args (request, jwt_payload, done_callback).
                    */
                    passReqToCallback?: false;
                    };

                      type StrategyOptionsWithRequest

                      type StrategyOptionsWithRequest = StrategyOptionsWithSecret & {
                      /**
                      * If true, the verify callback will be called with args (request, jwt_payload, done_callback).
                      */
                      passReqToCallback: true;
                      };

                        type StrategyOptionsWithSecret

                        type StrategyOptionsWithSecret =
                        | Omit<WithSecretOrKey, 'secretOrKeyProvider'>
                        | Omit<WithSecretOrKeyProvider, 'secretOrKey'>;

                          type VerifyCallback

                          type VerifyCallback = (payload: any, done: VerifiedCallback) => void;
                          • Callback used to verify the JWT payload.

                          type VerifyCallbackWithRequest

                          type VerifyCallbackWithRequest<T = any> = (
                          req: T,
                          payload: any,
                          done: VerifiedCallback
                          ) => void;
                          • Callback used to verify the JWT payload with request.

                          Namespaces

                          namespace ExtractJwt

                          namespace ExtractJwt {}

                            function fromAuthHeaderAsBearerToken

                            fromAuthHeaderAsBearerToken: () => JwtFromRequestFunction;
                            • Creates an extractor function to retrieve a token from the authorization header as a Bearer token.

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            function fromAuthHeaderWithScheme

                            fromAuthHeaderWithScheme: (auth_scheme: string) => JwtFromRequestFunction;
                            • Creates an extractor function to retrieve a token from the authorization header with a specific scheme.

                              Parameter auth_scheme

                              The authorization scheme (e.g., 'Bearer').

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            function fromBodyField

                            fromBodyField: (field_name: string) => JwtFromRequestFunction;
                            • Creates an extractor function to retrieve a token from a field in the request body.

                              Parameter field_name

                              The name of the field to extract the token from.

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            function fromExtractors

                            fromExtractors: <T = any>(
                            extractors: Array<JwtFromRequestFunction<T>>
                            ) => JwtFromRequestFunction<T>;
                            • Creates an extractor function that combines multiple extractor functions.

                              Parameter extractors

                              An array of extractor functions.

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            function fromHeader

                            fromHeader: (header_name: string) => JwtFromRequestFunction;
                            • Creates an extractor function to retrieve a token from the request header.

                              Parameter header_name

                              The name of the header to extract the token from.

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            function fromUrlQueryParameter

                            fromUrlQueryParameter: (param_name: string) => JwtFromRequestFunction;
                            • Creates an extractor function to retrieve a token from a query parameter in the URL.

                              Parameter param_name

                              The name of the query parameter to extract the token from.

                              Returns

                              {JwtFromRequestFunction} A function that takes a request object and returns the extracted token.

                            Package Files (1)

                            Dependencies (2)

                            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/passport-jwt.

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