• Creates a new middleware, that checks, if Authorization header is valid or not.

    Parameters

    • scheme: string

      The scheme.

    • value: string

      The value, next to scheme.

    • Optional onValidationFailed: Nilable<HttpRequestHandler>

      The custom handler, that is invoked, if validation fails.

    Returns UniqueHttpMiddleware

    The new middleware.

    Example

    import createServer, { auth, AuthValidatorWithoutScheme, IHttpRequest, IHttpResponse } from '@egomobile/http-server'

    const checkBearer: AuthValidatorWithoutScheme = async (value: string, request: IHttpRequest, response: IHttpResponse) => {
    // client must submit something like
    // 'Authorization: Bearer myBearerValue'
    return value === 'myBearerValue'
    }

    const app = createServer()

    // check if authorization header uses 'Bearer' scheme
    // and its value matches all criteria of 'checkBearer()'
    app.get('/', auth('Bearer', checkBearer), async (response, response) => {
    // your code, if bearer value is valid
    })
  • Parameters

    Returns UniqueHttpMiddleware

  • Parameters

    Returns UniqueHttpMiddleware

Generated using TypeDoc