Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated JWT Token Verifier audience value #11

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading