@@ -17,6 +17,8 @@ import {
1717 SignupResponse ,
1818 UserRegistration ,
1919 UsersResponse ,
20+ ResponseCode ,
21+ ResponseStatus
2022} from './api.interface' ;
2123import { ApiService } from './api.service' ;
2224import { ConfigResolverService } from './config.resolver.service' ;
@@ -27,10 +29,12 @@ import { RefreshRequest } from '@fusionauth/typescript-client/build/src/FusionAu
2729import { ChangePasswordDTO } from './dto/changePassword.dto' ;
2830import { SentryInterceptor } from '../interceptors/sentry.interceptor' ;
2931import * as Sentry from '@sentry/node' ;
30- import { LoginDto } from './dto/login.dto' ;
32+ import { LoginDto , LoginWithUniqueIdDto } from './dto/login.dto' ;
3133import { SendOtpDto } from './dto/send-otp.dto' ;
3234import { VerifyOtpDto } from './dto/verify-otp.dto' ;
3335import { Throttle , SkipThrottle } from '@nestjs/throttler' ;
36+ import { ConfigService } from '@nestjs/config' ;
37+ import { v4 as uuidv4 } from 'uuid' ;
3438// eslint-disable-next-line @typescript-eslint/no-var-requires
3539const CryptoJS = require ( 'crypto-js' ) ;
3640
@@ -40,6 +44,7 @@ CryptoJS.lib.WordArray.words;
4044@UseInterceptors ( SentryInterceptor )
4145export class ApiController {
4246 constructor (
47+ private configService : ConfigService ,
4348 private readonly fusionAuthService : FusionauthService ,
4449 private readonly otpService : OtpService ,
4550 private readonly apiService : ApiService ,
@@ -358,4 +363,22 @@ export class ApiController {
358363 ) : Promise < any > {
359364 return await this . apiService . loginWithOtp ( user , authHeader ) ;
360365 }
366+
367+ @Post ( 'login-with-unique-id' )
368+ @UsePipes ( new ValidationPipe ( { transform : true } ) )
369+ async loginWithUniqueId (
370+ @Body ( ) user : LoginWithUniqueIdDto ,
371+ @Headers ( 'authorization' ) authHeader ,
372+ @Headers ( 'ADMIN-API-KEY' ) adminApiKey
373+ ) : Promise < any > {
374+ if ( adminApiKey != this . configService . get ( 'ADMIN_API_KEY' ) ) {
375+ const response : SignupResponse = new SignupResponse ( ) . init ( uuidv4 ( ) ) ;
376+ response . responseCode = ResponseCode . FAILURE ;
377+ response . params . err = 'UNAUTHORIZED' ;
378+ response . params . errMsg = 'Invalid admin api key' ;
379+ response . params . status = ResponseStatus . failure ;
380+ return response ;
381+ }
382+ return await this . apiService . loginWithUniqueId ( user , authHeader ) ;
383+ }
361384}
0 commit comments