### Class: authenticationcomponent = new AuthenticationComponent()

Properties

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
providers | `ProviderMap` |  | exported optional |

#### constructor() : AuthenticationComponent

### Interface: AuthenticationMetadata

Authentication metadata stored via Reflection API

Properties

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

### Function: authenticate

#### authenticate(strategyName: string, options: Object) : anonymous

Mark a controller method as requiring authenticated user.

Parameters

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.

### Function: getAuthenticateMetadata

#### getAuthenticateMetadata(controllerClass: Constructor<__type>, methodName: string) : AuthenticationMetadata | undefined

Fetch authentication metadata stored by `@authenticate` decorator.

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
controllerClass | `Constructor<__type>` |  |  | Target controller
methodName | `string` |  |  | Target method

### Namespace: AuthenticationBindings

Binding keys used by this component.

### const AuthenticationBindings.AUTH_ACTION = BindingKey.create<AuthenticateFn>( 'authentication.actions.authenticate', )

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);
        }
      }
    }

### const AuthenticationBindings.CURRENT_USER = BindingKey.create<UserProfile | undefined>( 'authentication.currentUser', )

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 }

### const AuthenticationBindings.METADATA = BindingKey.create<AuthenticationMetadata | undefined>( 'authentication.operationMetadata', )

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
        }
      }
    }

### const AuthenticationBindings.STRATEGY = BindingKey.create<Strategy | undefined>( 'authentication.strategy', )

Key used to bind an authentication strategy to the context for the authentication function to use.

    server
      .bind(AuthenticationBindings.STRATEGY)
      .toProvider(MyPassportStrategyProvider);

### const AUTHENTICATION_METADATA_KEY = MetadataAccessor.create< AuthenticationMetadata >('authentication.operationsMetadata')

The key used to store log-related via @loopback/metadata and reflection.

### Class: authmetadataprovider = new AuthMetadataProvider()

#### constructor(controllerClass: Constructor<__type>, methodName: string) : AuthMetadataProvider

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
controllerClass | `Constructor<__type>` |  |  |
methodName | `string` |  |  |

#### value() : AuthenticationMetadata | undefined

Returns:

AuthenticationMetadata

### Class: authenticateactionprovider = new AuthenticateActionProvider()

Properties

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
getStrategy | `Getter<Strategy>` |  | constructorProperty exported |
setCurrentUser | `Setter<UserProfile>` |  | constructorProperty exported |

#### constructor(getStrategy: Getter<Strategy>, setCurrentUser: Setter<UserProfile>) : AuthenticateActionProvider

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
getStrategy | `Getter<Strategy>` |  |  |
setCurrentUser | `Setter<UserProfile>` |  |  |

#### action(request: Request) : Promise<UserProfile | undefined>

The implementation of authenticate() sequence action.

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
request | `Request` |  |  | The incoming request provided by the REST layer

#### value() : AuthenticateFn

Returns:

authenticateFn

### Class: strategyadapter = new StrategyAdapter()

Adapter class to invoke passport-strategy

1. provides express dependencies to the passport strategies
2. provides shimming of requests for passport authentication
3. provides lifecycle similar to express to the passport-strategy
4. provides state methods to the strategy instance see: https://github.com/jaredhanson/passport

#### constructor(strategy: Strategy) : StrategyAdapter

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
strategy | `Strategy` |  |  | instance of a class which implements a passport-strategy;

#### authenticate(request: Request) : Promise<UserProfile>

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

Parameters

Name | Type | Default Value | Flags | Description
--- | --- | --- | --- | ---
request | `Request` |  |  | The incoming request.