import { BindingScope , extensionPoint , extensions , Getter , inject , Provider , } from '@loopback/core' ; import { AuthenticationBindings } from '../keys' ; import { AuthenticationMetadata , AuthenticationStrategy , AUTHENTICATION_STRATEGY_NOT_FOUND , } from '../types' ; example @ extensionPoint ( AuthenticationBindings . AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME , { scope : BindingScope . TRANSIENT } ) export class AuthenticationStrategyProvider implements Provider < AuthenticationStrategy [ ] | undefined > { constructor ( @ extensions ( ) protected authenticationStrategies , @ inject ( AuthenticationBindings . METADATA ) protected metadata ? ) { } async value ( ) { if ( ! this . metadata ?. length ) { return undefined ; } return this . findAuthenticationStrategies ( this . metadata ) ; } private async findAuthenticationStrategies ( metadata ) { const strategies = [ ] ; const existingStrategies = await this . authenticationStrategies ( ) ; const findStrategy = ( name ) => { const strategy = existingStrategies . find ( a => a . name === name ) ; if ( ! strategy ) { const error = new Error ( `The strategy '${ name }' is not available.` ) ; Object . assign ( error , { code : AUTHENTICATION_STRATEGY_NOT_FOUND , } ) ; throw error ; } return strategy ; } ; for ( const data of metadata ) { const strategy = findStrategy ( data . strategy ) ; strategies . push ( strategy ) ; } return strategies ; } }