| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| providers |
ProviderMap
|
exported optional |
Authentication metadata stored via Reflection API
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| options |
Object
|
exported optional |
Authentication metadata stored via Reflection API |
|
| strategy |
string
|
exported |
Authentication metadata stored via Reflection API |
Mark a controller method as requiring authenticated user.
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| strategyName |
string
|
The name of the authentication strategy to use. |
||
| options |
Object
|
optional |
Additional options to configure the authentication. |
Fetch authentication metadata stored by @authenticate decorator.
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| controllerClass |
Constructor<__type>
|
Target controller |
||
| methodName |
string
|
Target method |
Binding keys used by this component.
Key used to inject the authentication function into the sequence.
class MySequence implements SequenceHandler {
constructor(
@inject(AuthenticationBindings.AUTH_ACTION)
protected authenticateRequest: AuthenticateFn,
// ... other sequence action injections
) {}
async handle(context: RequestContext) {
try {
const {request, response} = context;
const route = this.findRoute(request);
// Authenticate
await this.authenticateRequest(request);
// Authentication successful, proceed to invoke controller
const args = await this.parseParams(request, route);
const result = await this.invoke(route, args);
this.send(response, result);
} catch (err) {
this.reject(context, err);
}
}
}
Key used to inject the user instance retrieved by the authentication function
class MyController { constructor( @inject(AuthenticationBindings.CURRENT_USER) private user: UserProfile, ) {}
// ... routes that may need authentication }
Key used to inject authentication metadata, which is used to determine whether a request requires authentication or not.
class MyPassportStrategyProvider implements Provider<Strategy | undefined> {
constructor(
@inject(AuthenticationBindings.METADATA)
private metadata: AuthenticationMetadata,
) {}
value(): ValueOrPromise<Strategy | undefined> {
if (this.metadata) {
const name = this.metadata.strategy;
// logic to determine which authentication strategy to return
}
}
}
Key used to bind an authentication strategy to the context for the authentication function to use.
server
.bind(AuthenticationBindings.STRATEGY)
.toProvider(MyPassportStrategyProvider);
The key used to store log-related via @loopback/metadata and reflection.
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| controllerClass |
Constructor<__type>
|
|
||
| methodName |
string
|
|
AuthenticationMetadata
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| getStrategy |
Getter<Strategy>
|
constructorProperty exported |
|
|
| setCurrentUser |
Setter<UserProfile>
|
constructorProperty exported |
|
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| getStrategy |
Getter<Strategy>
|
|
||
| setCurrentUser |
Setter<UserProfile>
|
|
The implementation of authenticate() sequence action.
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| request |
Request
|
The incoming request provided by the REST layer |
authenticateFn
Adapter class to invoke passport-strategy
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| strategy |
Strategy
|
instance of a class which implements a passport-strategy; |
The function to invoke the contained passport strategy.
1. Create an instance of the strategy
2. add success and failure state handlers
3. authenticate using the strategy
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
| request |
Request
|
The incoming request. |
interface definition of a function which accepts a request and returns an authenticated user
interface definition of a user profile http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims
| Name | Type | Default Value | Flags | Description |
|---|---|---|---|---|
undefined | string
|
exported optional |
interface definition of a user profile http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims |
||
| id |
string
|
exported |
interface definition of a user profile http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims |
|
| name |
undefined | string
|
exported optional |
interface definition of a user profile http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims |