Skip to content

Commit

Permalink
Updated JWT Token Verifier audience value
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitKandimalla committed Apr 17, 2024
1 parent 4166bd3 commit 11492bd
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
canActivate(context: ExecutionContext): boolean {
const oktaJwtVerifier = new OktaJwtVerifier({
issuer: process.env.ISSUER,
clientId: process.env.CLIENT_ID,
});

const request = context.switchToHttp().getRequest();
Expand All @@ -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;
}

Expand Down

0 comments on commit 11492bd

Please sign in to comment.