From 11492bd275ea16d6a5054fc5396a7661d81d9ad6 Mon Sep 17 00:00:00 2001 From: Rohit Kandimalla Date: Wed, 17 Apr 2024 15:54:20 -0400 Subject: [PATCH] Updated JWT Token Verifier audience value --- src/auth/auth.guard.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/auth/auth.guard.ts b/src/auth/auth.guard.ts index d11cdaf..7512e93 100644 --- a/src/auth/auth.guard.ts +++ b/src/auth/auth.guard.ts @@ -8,15 +8,15 @@ import { import { JwtService } from '@nestjs/jwt'; import * as OktaJwtVerifier from '@okta/jwt-verifier'; import { Request } from 'express'; +import * as process from "process"; @Injectable() export class AuthGuard implements CanActivate { constructor(private jwtService: JwtService) {} - async canActivate(context: ExecutionContext): Promise { + canActivate(context: ExecutionContext): boolean { const oktaJwtVerifier = new OktaJwtVerifier({ issuer: process.env.ISSUER, - clientId: process.env.CLIENT_ID, }); const request = context.switchToHttp().getRequest(); @@ -25,15 +25,15 @@ export class AuthGuard implements CanActivate { if (!token) { throw new UnauthorizedException('Token not present'); } - try { - const oktaToken = await oktaJwtVerifier.verifyAccessToken( - token, - 'api://default', - ); - request['user'] = oktaToken.claims.sub; - } catch { - throw new UnauthorizedException('Token not valid'); - } + oktaJwtVerifier + .verifyAccessToken(token, `${process.env.CLIENT_ID}`) + .then((oktaToken) => { + request['user'] = oktaToken.claims.sub; + }) + .catch((error) => { + console.debug('Error while verifying tokens', error); + throw new UnauthorizedException('Token not valid'); + }); return true; }