File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 1
1
TOPCODER_API_BASE_URL = " https://api.topcoder-dev.com/v5"
2
+ AUTH0_CERT = "-----BEGIN RSA PUBLIC KEY-----
3
+ MIIBCgKCAQEArAV0dmDkedFdlaQ6KQiqUv+UGshfMXx/4jJCLZ9802ynJqAvIt+Z
4
+ V7EiPqjc2J1xVfJJEvQ9ZS5A2TFWAk16NUTU4LN+TkjEnqeg+LlUPWY3Y4RXa2OU
5
+ mmSIG2GsbR0Kx7b3Y3bYdKBNT0vDe396v/TXi0OQMnz8HZ88/hPvg3V7V34kpxon
6
+ XcG/nSm6AtNE7VWey+23oDon1wRon8+qr/JsLLlfnVzYdSujiKvz3vyB/0REDREm
7
+ BHMKuGsgiBjJ7xHNxaJvBzrwdArogHSxEPmT6gNr5rZeXmJUWzrpQIstMXA9gEXX
8
+ LfKzG61idXFIwBa6t5YBCCMx+hoCxhcEiwIDAQAB
9
+ -----END RSA PUBLIC KEY-----"
10
+ AUTH0_CLIENT_ID = BXWXUWnilVUPdN01t2Se29Tw2ZYNGZvH
2
11
3
12
DB_USERNAME = topcoderuser
4
13
DB_PASSWORD = randompassword
Original file line number Diff line number Diff line change 1
- import { Injectable , NestMiddleware } from '@nestjs/common' ;
1
+ import {
2
+ Injectable ,
3
+ NestMiddleware ,
4
+ UnauthorizedException ,
5
+ } from '@nestjs/common' ;
2
6
import * as jwt from 'jsonwebtoken' ;
3
7
4
8
@Injectable ( )
@@ -10,11 +14,15 @@ export class TokenValidatorMiddleware implements NestMiddleware {
10
14
return next ( ) ;
11
15
}
12
16
13
- // TODO: use jwt.verify to verify against auth0 secret
14
- const decoded : any = jwt . decode ( idToken , {
15
- ignoreExpiration : true ,
16
- ignoreNotBefore : true ,
17
- } ) ;
17
+ let decoded : any ;
18
+ try {
19
+ decoded = jwt . verify ( idToken , process . env . AUTH0_CERT , {
20
+ audience : process . env . AUTH0_CLIENT_ID ,
21
+ } ) ;
22
+ } catch ( error ) {
23
+ console . error ( 'Error verifying JWT' , error ) ;
24
+ throw new UnauthorizedException ( 'Invalid or expired JWT!' ) ;
25
+ }
18
26
19
27
// TODO: verify decoded.aud
20
28
if ( ! decoded ) {
You can’t perform that action at this time.
0 commit comments