File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ BHMKuGsgiBjJ7xHNxaJvBzrwdArogHSxEPmT6gNr5rZeXmJUWzrpQIstMXA9gEXX
8
8
LfKzG61idXFIwBa6t5YBCCMx+hoCxhcEiwIDAQAB
9
9
-----END RSA PUBLIC KEY-----"
10
10
AUTH0_CLIENT_ID = BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH
11
+ AUTH0_M2M_AUDIENCE = https://m2m.topcoder-dev.com/
11
12
12
13
DB_USERNAME = topcoderuser
13
14
DB_PASSWORD = randompassword
Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ export class AuthGuard implements CanActivate {
50
50
[ context . getHandler ( ) , context . getClass ( ) ] ,
51
51
) ;
52
52
53
- const reqScopes = req . m2mTokenScope . split ( ' ' )
54
- if ( reqScopes . some ( reqScope => allowedM2mScopes . includes ( reqScope ) ) ) {
53
+ const reqScopes = req . m2mTokenScope . split ( ' ' ) ;
54
+ if ( reqScopes . some ( ( reqScope ) => allowedM2mScopes . includes ( reqScope ) ) ) {
55
55
return true ;
56
56
}
57
57
return false ;
Original file line number Diff line number Diff line change @@ -16,23 +16,28 @@ export class TokenValidatorMiddleware implements NestMiddleware {
16
16
17
17
let decoded : any ;
18
18
try {
19
- decoded = jwt . verify ( idToken , process . env . AUTH0_CERT , {
20
- audience : process . env . AUTH0_CLIENT_ID ,
21
- } ) ;
19
+ decoded = jwt . verify ( idToken , process . env . AUTH0_CERT ) ;
22
20
} catch ( error ) {
23
21
console . error ( 'Error verifying JWT' , error ) ;
24
22
throw new UnauthorizedException ( 'Invalid or expired JWT!' ) ;
25
23
}
26
24
27
- // TODO: verify decoded.aud
28
25
if ( ! decoded ) {
29
26
req . idTokenVerified = false ;
30
27
return next ( ) ;
31
28
}
32
29
33
- req . idTokenVerified = true ;
34
30
req . isM2M = ! ! decoded . scope ;
31
+ const aud = req . isM2M
32
+ ? process . env . AUTH0_M2M_AUDIENCE
33
+ : process . env . AUTH0_CLIENT_ID ;
34
+
35
+ if ( decoded . aud !== aud ) {
36
+ req . idTokenVerified = false ;
37
+ return next ( ) ;
38
+ }
35
39
40
+ req . idTokenVerified = true ;
36
41
if ( decoded . scope ) {
37
42
req . m2mTokenScope = decoded . scope ;
38
43
req . m2mTokenAudience = decoded . aud ;
You can’t perform that action at this time.
0 commit comments