Class HttpHandlers<Request, Response>Abstract

Low-level HTTP request handlers and utility functions that can be used by Express, Next, or other server frameworks.

Type Parameters

Hierarchy

Constructors

Properties

authErrorHandler: AuthErrorHandler<Request, Response> = ...

Executed when encountering an authentication error.

See

isAuthError

Param

req

Param

res

Param

error

Returns

void

client: main

unologin instance

loginSuccessHandler: null | LoginSuccessHandler<Request, Response> = null

Accessors

  • get cookies(): {
        login: {
            name: string;
            options: CookieOptions;
        };
        loginState: {
            name: string;
            options: CookieOptions;
        };
    }
  • Returns {
        login: {
            name: string;
            options: CookieOptions;
        };
        loginState: {
            name: string;
            options: CookieOptions;
        };
    }

    • login: {
          name: string;
          options: CookieOptions;
      }
      • name: string
      • options: CookieOptions
    • loginState: {
          name: string;
          options: CookieOptions;
      }
      • name: string
      • options: CookieOptions

Methods

  • Completes cookie options.

    Returns

    default cookie options

    Parameters

    • opts: CookieOptions

      cookie options

    Returns CookieOptions

  • Internal

    Result of getUserTokenOptional may be stored in with the response object.

    This function acts as a helper to retrieve the cached value.

    This function is meant to be used in conjunction with Express-like frameworks where one middleware function is called after another, passing values using res.locals.

    See

    setCachedUserToken

    Returns

    parsed user token cached in res.locals

    Parameters

    • res: Response

      res

    Returns null | UserToken

  • Get login cookie from cookies object.

    Returns

    cookie value

    Parameters

    • cookies: {
          [k: string]: string | undefined;
      }

      cookies

      • [k: string]: string | undefined

    Returns null | string

  • Returns

    URL

    Parameters

    • req: Request

      req

    • _: Response

      res (not used)

    Returns URL

  • Returns a UserHandle from the current request. Returns null if the request contains no login information.

    IMPORTANT:

    This function is synchronous and the UserHandle can therefore not be trusted to be authenticated.

    The returned UserHandle can however be used in any API call that accepts a UserHandle as a parameter.

    In this case, the authentication happens on the unologin API.

    Use getUserTokenOptional for optional authentication. Use getUserToken for required authentication.

    Returns

    UserHandle | null

    Parameters

    • req: Request

      req

    • res: Response

      res

    Returns null | UserHandle

  • Authenticates the user and returns a Promise to the UserToken.

    Requires the user to be logged in.

    The resolved UserToken is authenticated and can be trusted.

    See

    getUserTokenOptional for optional authentication.

    Throws

    APIError 403 unauthorized if not logged in.

    Throws

    APIError 403 unauthorized if login token invalid.

    Returns

    Promise

    Parameters

    • req: Request

      req

    • res: Response

      res

    Returns Promise<UserToken>

  • Authenticates the user and returns a Promise to the UserToken.

    Does not require the user to be logged in. Does nothing if no login cookie is present and returns null.

    The resolved UserToken is authenticated and can be trusted if not null.

    Requires a cookie parser.

    See

    getUserToken for required authentication.

    Returns

    Promise

    Parameters

    • req: Request

      req

    • res: Response

      res

    Returns Promise<null | UserToken>

  • Internal

    Handles the unologin login event. Returns a URL to redirect the user to.

    Returns

    Promise to redirect the user to

    Parameters

    • req: Request

      req

    • res: Response

      res

    Returns Promise<{
        url: URL;
    }>

  • Add a callback that is called after the login event has finished but before the response is sent to the client.

    The UserToken passed to handler is authenticated an can be trusted.

    Returns

    void

    Parameters

    Returns void

  • Resets/deletes login cookies.

    Returns

    void

    Parameters

    • req: Request

      req

    • res: Response

      res

    Returns void

  • Internal

    Framework specific implementation required.

    Parameters

    • req: Request

      req

    • res: Response

      res

    • name: string

      name

    • value: string

      value

    • options: CookieOptions

      cookie options

    Returns void

  • Internal

    Set the login cookies for a response.

    Returns

    void

    Parameters

    • req: Request

      req

    • res: Response

      rest

    • cookie: LoginCookie

      cookie to set

    • options: CookieOptions = {}

      cookie options

    Returns void

Generated using TypeDoc