// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved. // Node module: @loopback/authentication-jwt // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT 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[] = [ // token bindings 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), // user bindings Binding.bind(UserServiceBindings.USER_SERVICE).toClass(MyUserService), Binding.bind(UserServiceBindings.USER_REPOSITORY).toClass(UserRepository), Binding.bind(UserServiceBindings.USER_CREDENTIALS_REPOSITORY).toClass( UserCredentialsRepository, ), createBindingFromClass(SecuritySpecEnhancer), ///refresh bindings Binding.bind(RefreshTokenServiceBindings.REFRESH_TOKEN_SERVICE).toClass( RefreshtokenService, ), // Refresh token bindings 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, ), //refresh token repository binding Binding.bind(RefreshTokenServiceBindings.REFRESH_REPOSITORY).toClass( RefreshTokenRepository, ), ]; constructor(@inject(CoreBindings.APPLICATION_INSTANCE) app: Application) { registerAuthenticationStrategy(app, JWTAuthenticationStrategy); } }