Skip to content

Commit

Permalink
Merge pull request #11 from MeasureAuthoringTool/feature/Health-check
Browse files Browse the repository at this point in the history
Updated JWT Token Verifier audience value
  • Loading branch information
RohitKandimalla authored Apr 17, 2024
2 parents de69b8c + 80cabae commit f7dad14
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 f7dad14

Please sign in to comment.