Interface TotpMiddlewares<U>

This object contains the authenticate() function which is the main middleware, as well as additional functions for generating tokens and URLs.

Type Parameters

  • U

Hierarchy

  • TotpMiddlewares

Methods

  • Middleware for authenticating a user, using their secret and the token provided in the request.

    See

    Parameters

    • Optional options: Partial<TotpApiOptions<U>>

      Options for the middleware.

    Returns ((req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: (() => void)) => Promise<void>)

      • (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: (() => void)): Promise<void>
      • Middleware for authenticating a user, using their secret and the token provided in the request.

        See

        Parameters

        • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
        • res: Response<any, Record<string, any>>
        • next: (() => void)
            • (): void
            • Returns void

        Returns Promise<void>

  • Generates a random, 32-byte secret key. You can attach this to your user object or DB however you want.

    Returns string

  • Function for generating a QR code for a user from a given secret and username.

    This returns a PNG image as a data URL.

    Returns

    The QR code as a data URL.

    Parameters

    • username: string

      The username to use for generating the URL.

    • secret: string

      The secret to use for generating the URL.

    Returns Promise<string>

  • Function for generating a QR code for a user from a given secret and username.

    This writes the QR code directly to a file, which you can later use to serve to the user.

    Parameters

    • username: string

      The username to use for generating the URL.

    • secret: string

      The secret to use for generating the URL.

    • filename: string

      The path of the file to write the QR image to.

    Returns Promise<void>

  • Function for generating a QR code for a user from a given secret and username.

    • If filename is provided, this writes the QR code directly to that path, which you can later use to serve to the user.
    • If filename is omitted (or blank), this returns a PNG image as a data URL.

    Parameters

    • username: string

      The username to use for generating the URL.

    • secret: string

      The secret to use for generating the URL.

    • Optional filename: string

      If provided, will use as path of the file to write the QR image to.

    Returns Promise<string | void>

  • Function for generating a secret URL for a user from a given secret and username.

    Returns

    The URL for the user.

    Parameters

    • username: string

      The username to use for generating the URL.

    • secret: string

      The secret to use for generating the URL.

    Returns string

  • Verifies a given token against a given secret. If the provided token is equal to the generated token for given secret, it returns true. Otherwise, it returns false.

    Returns

    true if the token is valid, false otherwise.

    Parameters

    • secret: string

      The secret key of the user.

    • token: string

      The request token to verify against.

    Returns boolean

  • Returns the user, only if the token is valid. Otherwise, it returns undefined.

    Returns

    The user, or undefined if the token is invalid.

    Parameters

    • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

      The request object.

    Returns Promise<undefined | U>

Generated using TypeDoc