Verifying an Okta token from Node with OktaJwtVerifier

When instantiating a new instance of OktaJwtVerifier from a nest.js service I get:

“TypeError: jwt_verifier_1.default is not a constructor”

This despite following the official guide Build Your First NestJS Application | Okta Developer

a code snippet would be helpful, or are you saying the the example provided by the URL is not working?

import { Injectable } from ‘@nestjs/common’;
import OktaJwtVerifier from ‘@okta/jwt-verifier’;

@Injectable()
export class OktaTokenValidatorService {
private oktaVerifier: any;
private audience: string;

constructor() {
this.oktaVerifier = new OktaJwtVerifier({
issuer: ‘https://dev-xyz.okta.com/oauth2/default’,
clientId: ‘xyzxyzxyz’,
});

this.audience = 'xyzxyzxyz'

}

async validateToken(token: string): Promise {
const jwt = await this.oktaVerifier.verifyAccessToken(token, this.audience);
return jwt;
}
}

The resolution to this issue was that the import for OktaJwtVerifier should in fact be the following:
import * as OktaJwtVerifier from '@okta/jwt-verifier';

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.