Magek Framework
    Preparing search index...

    Function verifyJWT

    • Verifies a JWT token using a key or key resolver function and returns a Magek UserEnvelope.

      Parameters

      • token: string

        The token to verify

      • issuer: string

        The issuer of the token

      • key: Secret | GetPublicKeyOrSecret

        The public key to use to verify the token or a function that will resolve a jwksUri to get the public key. The function can be generated using the getKeyWithClient function.

      • verifier: {
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options: VerifyOptions & {},
            ): Jwt;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions & {},
            ): string | JwtPayload;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions,
            ): string | Jwt | JwtPayload;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                callback?: VerifyCallback<string | JwtPayload>,
            ): void;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options: VerifyOptions & {},
                callback?: VerifyCallback<Jwt>,
            ): void;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions & {},
                callback?: VerifyCallback<string | JwtPayload>,
            ): void;
            (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions,
                callback?: VerifyCallback<string | Jwt | JwtPayload>,
            ): void;
        } = jwt.verify

        Optional custom JWT verify function (defaults to jsonwebtoken's verify)

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options: VerifyOptions & {},
            ): Jwt
          • 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.

            Parameters

            • token: string
            • secretOrPublicKey: Buffer<ArrayBufferLike> | Secret | PublicKeyInput | JsonWebKeyInput
            • options: VerifyOptions & {}

            Returns Jwt

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions & {},
            ): string | JwtPayload
          • 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.

            Parameters

            • token: string
            • secretOrPublicKey: Buffer<ArrayBufferLike> | Secret | PublicKeyInput | JsonWebKeyInput
            • Optionaloptions: VerifyOptions & {}

            Returns string | JwtPayload

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions,
            ): string | Jwt | JwtPayload
          • 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.

            Parameters

            • token: string
            • secretOrPublicKey: Buffer<ArrayBufferLike> | Secret | PublicKeyInput | JsonWebKeyInput
            • Optionaloptions: VerifyOptions

            Returns string | Jwt | JwtPayload

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                callback?: VerifyCallback<string | JwtPayload>,
            ): void
          • 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

            Parameters

            • token: string
            • secretOrPublicKey:
                  | Buffer<ArrayBufferLike>
                  | Secret
                  | GetPublicKeyOrSecret
                  | PublicKeyInput
                  | JsonWebKeyInput
            • Optionalcallback: VerifyCallback<string | JwtPayload>

            Returns void

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options: VerifyOptions & {},
                callback?: VerifyCallback<Jwt>,
            ): 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.

            Parameters

            • token: string
            • secretOrPublicKey:
                  | Buffer<ArrayBufferLike>
                  | Secret
                  | GetPublicKeyOrSecret
                  | PublicKeyInput
                  | JsonWebKeyInput
            • options: VerifyOptions & {}
            • Optionalcallback: VerifyCallback<Jwt>

            Returns void

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions & {},
                callback?: VerifyCallback<string | 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.

            Parameters

            • token: string
            • secretOrPublicKey:
                  | Buffer<ArrayBufferLike>
                  | Secret
                  | GetPublicKeyOrSecret
                  | PublicKeyInput
                  | JsonWebKeyInput
            • Optionaloptions: VerifyOptions & {}
            • Optionalcallback: VerifyCallback<string | JwtPayload>

            Returns void

          • (
                token: string,
                secretOrPublicKey:
                    | Buffer<ArrayBufferLike>
                    | Secret
                    | GetPublicKeyOrSecret
                    | PublicKeyInput
                    | JsonWebKeyInput,
                options?: VerifyOptions,
                callback?: VerifyCallback<string | Jwt | 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.

            Parameters

            • token: string
            • secretOrPublicKey:
                  | Buffer<ArrayBufferLike>
                  | Secret
                  | GetPublicKeyOrSecret
                  | PublicKeyInput
                  | JsonWebKeyInput
            • Optionaloptions: VerifyOptions
            • Optionalcallback: VerifyCallback<string | Jwt | JwtPayload>

            Returns void

      Returns Promise<DecodedToken>

      A promise that resolves to the DecodedToken object