@@ -17,6 +17,8 @@ import {
17
17
SignupResponse ,
18
18
UserRegistration ,
19
19
UsersResponse ,
20
+ ResponseCode ,
21
+ ResponseStatus
20
22
} from './api.interface' ;
21
23
import { ApiService } from './api.service' ;
22
24
import { ConfigResolverService } from './config.resolver.service' ;
@@ -27,10 +29,12 @@ import { RefreshRequest } from '@fusionauth/typescript-client/build/src/FusionAu
27
29
import { ChangePasswordDTO } from './dto/changePassword.dto' ;
28
30
import { SentryInterceptor } from '../interceptors/sentry.interceptor' ;
29
31
import * as Sentry from '@sentry/node' ;
30
- import { LoginDto } from './dto/login.dto' ;
32
+ import { LoginDto , LoginWithUniqueIdDto } from './dto/login.dto' ;
31
33
import { SendOtpDto } from './dto/send-otp.dto' ;
32
34
import { VerifyOtpDto } from './dto/verify-otp.dto' ;
33
35
import { Throttle , SkipThrottle } from '@nestjs/throttler' ;
36
+ import { ConfigService } from '@nestjs/config' ;
37
+ import { v4 as uuidv4 } from 'uuid' ;
34
38
// eslint-disable-next-line @typescript-eslint/no-var-requires
35
39
const CryptoJS = require ( 'crypto-js' ) ;
36
40
@@ -40,6 +44,7 @@ CryptoJS.lib.WordArray.words;
40
44
@UseInterceptors ( SentryInterceptor )
41
45
export class ApiController {
42
46
constructor (
47
+ private configService : ConfigService ,
43
48
private readonly fusionAuthService : FusionauthService ,
44
49
private readonly otpService : OtpService ,
45
50
private readonly apiService : ApiService ,
@@ -358,4 +363,22 @@ export class ApiController {
358
363
) : Promise < any > {
359
364
return await this . apiService . loginWithOtp ( user , authHeader ) ;
360
365
}
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
+ }
361
384
}
0 commit comments