import { AuthenticateFn , AuthenticationBindings , AuthenticationComponent , } from '@loopback/authentication' ; import { inject } from '@loopback/core' ; import { FindRoute , InvokeMethod , ParseParams , Reject , RequestContext , RestApplication , RestBindings , RestServer , Send , SequenceHandler , } from '@loopback/rest' ; import { MyUser } from '@loopback/mock-oauth2-provider' ; import { StrategyAdapter } from '../../../strategy-adapter' ; import { extensionFor } from '@loopback/core' ; const SequenceActions = RestBindings . SequenceActions ; let app ; let server ; export class MySequence implements SequenceHandler { constructor ( @ inject ( SequenceActions . FIND_ROUTE ) protected findRoute , @ inject ( SequenceActions . PARSE_PARAMS ) protected parseParams , @ inject ( SequenceActions . INVOKE_METHOD ) protected invoke , @ inject ( SequenceActions . SEND ) protected send , @ inject ( SequenceActions . REJECT ) protected reject , @ inject ( AuthenticationBindings . AUTH_ACTION ) protected authenticateRequest ) { } async handle ( context ) { try { const { request , response } = context ; const route = this . findRoute ( request ) ; await this . authenticateRequest ( request ) ; const args = await this . parseParams ( request , route ) ; const result = await this . invoke ( route , args ) ; this . send ( response , result ) ; } catch ( error ) { this . reject ( context , error ) ; return ; } } } export function simpleRestApplication ( ) { app = new RestApplication ( ) ; app . component ( AuthenticationComponent ) ; return app ; } export async function configureApplication ( authStrategy , authKey ) { server = await app . getServer ( RestServer ) ; app . bind ( authKey ) . to ( authStrategy ) . apply ( extensionFor ( AuthenticationBindings . AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME ) ) ; server . sequence ( MySequence ) ; }