@@ -8,15 +8,15 @@ import {
8
8
import { JwtService } from '@nestjs/jwt' ;
9
9
import * as OktaJwtVerifier from '@okta/jwt-verifier' ;
10
10
import { Request } from 'express' ;
11
+ import * as process from 'process' ;
11
12
12
13
@Injectable ( )
13
14
export class AuthGuard implements CanActivate {
14
15
constructor ( private jwtService : JwtService ) { }
15
16
16
- async canActivate ( context : ExecutionContext ) : Promise < boolean > {
17
+ canActivate ( context : ExecutionContext ) : boolean {
17
18
const oktaJwtVerifier = new OktaJwtVerifier ( {
18
19
issuer : process . env . ISSUER ,
19
- clientId : process . env . CLIENT_ID ,
20
20
} ) ;
21
21
22
22
const request = context . switchToHttp ( ) . getRequest ( ) ;
@@ -25,15 +25,15 @@ export class AuthGuard implements CanActivate {
25
25
if ( ! token ) {
26
26
throw new UnauthorizedException ( 'Token not present' ) ;
27
27
}
28
- try {
29
- const oktaToken = await oktaJwtVerifier . verifyAccessToken (
30
- token ,
31
- 'api://default' ,
32
- ) ;
33
- request [ 'user' ] = oktaToken . claims . sub ;
34
- } catch {
35
- throw new UnauthorizedException ( 'Token not valid' ) ;
36
- }
28
+ oktaJwtVerifier
29
+ . verifyAccessToken ( token , ` ${ process . env . CLIENT_ID } ` )
30
+ . then ( ( oktaToken ) => {
31
+ request [ 'user' ] = oktaToken . claims . sub ;
32
+ } )
33
+ . catch ( ( error ) => {
34
+ console . debug ( 'Error while verifying tokens' , error ) ;
35
+ throw new UnauthorizedException ( 'Token not valid' ) ;
36
+ } ) ;
37
37
return true ;
38
38
}
39
39
0 commit comments