import { registerAuthenticationStrategy } from '@loopback/authentication' ; import { Application , Binding , Component , CoreBindings , createBindingFromClass , inject , } from '@loopback/core' ; import { RefreshTokenConstants , RefreshTokenServiceBindings , TokenServiceBindings , TokenServiceConstants , UserServiceBindings , } from './keys' ; import { RefreshTokenRepository , UserCredentialsRepository , UserRepository , } from './repositories' ; import { MyUserService , RefreshtokenService } from './services' ; import { JWTAuthenticationStrategy } from './services/jwt.auth.strategy' ; import { JWTService } from './services/jwt.service' ; import { SecuritySpecEnhancer } from './services/security.spec.enhancer' ; export class JWTAuthenticationComponent implements Component { bindings : Binding [ ] = [ Binding . bind ( TokenServiceBindings . TOKEN_SECRET ) . to ( TokenServiceConstants . TOKEN_SECRET_VALUE ) , Binding . bind ( TokenServiceBindings . TOKEN_EXPIRES_IN ) . to ( TokenServiceConstants . TOKEN_EXPIRES_IN_VALUE ) , Binding . bind ( TokenServiceBindings . TOKEN_SERVICE ) . toClass ( JWTService ) , Binding . bind ( UserServiceBindings . USER_SERVICE ) . toClass ( MyUserService ) , Binding . bind ( UserServiceBindings . USER_REPOSITORY ) . toClass ( UserRepository ) , Binding . bind ( UserServiceBindings . USER_CREDENTIALS_REPOSITORY ) . toClass ( UserCredentialsRepository ) , createBindingFromClass ( SecuritySpecEnhancer ) , Binding . bind ( RefreshTokenServiceBindings . REFRESH_TOKEN_SERVICE ) . toClass ( RefreshtokenService ) , Binding . bind ( RefreshTokenServiceBindings . REFRESH_SECRET ) . to ( RefreshTokenConstants . REFRESH_SECRET_VALUE ) , Binding . bind ( RefreshTokenServiceBindings . REFRESH_EXPIRES_IN ) . to ( RefreshTokenConstants . REFRESH_EXPIRES_IN_VALUE ) , Binding . bind ( RefreshTokenServiceBindings . REFRESH_ISSUER ) . to ( RefreshTokenConstants . REFRESH_ISSUER_VALUE ) , Binding . bind ( RefreshTokenServiceBindings . REFRESH_REPOSITORY ) . toClass ( RefreshTokenRepository ) , ] ; constructor ( @ inject ( CoreBindings . APPLICATION_INSTANCE ) app ) { registerAuthenticationStrategy ( app , JWTAuthenticationStrategy ) ; } }