The scheme.
The value, next to scheme.
Optional
onValidationFailed: Nilable<HttpRequestHandler>The custom handler, that is invoked, if validation fails.
The new middleware.
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
})
Optional
onValidationFailed: Nilable<HttpRequestHandler>Optional
onValidationFailed: Nilable<HttpRequestHandler>Generated using TypeDoc
Creates a new middleware, that checks, if Authorization header is valid or not.