Skip to main content

Class: AuthMiddleware

Defined in: service-core/src/auth/AuthMiddleware.ts:18

A set of common utilities for performing authentication using one or more strategies.

Constructors

Constructor

new AuthMiddleware(): AuthMiddleware

Returns

AuthMiddleware

Properties

strategies

readonly strategies: Map<string, AuthStrategy>

Defined in: service-core/src/auth/AuthMiddleware.ts:29

The authentication strategies that have been registered.

Methods

authenticate()

authenticate(strategies, req, res?, required?): Promise<AuthResult | undefined>

Defined in: service-core/src/auth/AuthMiddleware.ts:52

Performs authentication of the given request using one of the provided strategies.

Parameters

strategies

string[]

The list of strategy names to attempt authentication with.

req

HttpRequest

The request containing data to perform authenticate with.

res?

HttpResponse

The response to use when writing back directly to the client.

required?

boolean

Set to true to if authentication is required to pass, otherwise set to false.

Returns

Promise<AuthResult | undefined>


authenticateSync()

authenticateSync(strategies, req, res?, required?): AuthResult | undefined

Defined in: service-core/src/auth/AuthMiddleware.ts:90

Performs authentication of the given request using one of the provided strategies.

This is the synchronous version of authenticate that performs blocking based authentication.

Parameters

strategies

string[]

The list of strategy names to attempt authentication with.

req

HttpRequest

The request containing data to perform authenticate with.

res?

HttpResponse

The response to use when writing back directly to the client.

required?

boolean

Set to true to if authentication is required to pass, otherwise set to false.

Returns

AuthResult | undefined


authWebSocket()

authWebSocket(required): RequestHandler

Defined in: service-core/src/auth/AuthMiddleware.ts:131

Returns a request handler function that will perform authentication of a websocket connection. Authentication can be handled in two ways:

  1. Authorization header
  2. Negotiation via handshake

This middleware function primarily provides the implementation for item 2 above.

Parameters

required

boolean

Set to true to indicate that auth is required, otherwise false.

Returns

RequestHandler


register()

register(name, strategy): void

Defined in: service-core/src/auth/AuthMiddleware.ts:276

Registers the provided authentication strategy to be used

Parameters

name

string

The name of the authentication type to associate the given strategy with

strategy

AuthStrategy

The strategy to register

Returns

void