okta-sdk-nodejs
okta-sdk-nodejs copied to clipboard
jwt.isExpired() throws "TypeError: Cannot read property 'exp' of undefined"
I'm hitting a weird problem trying to call the isExpired function on a Jwt.
Setup: Single-page web app is sending access token to a server. Server is verifying the token.
Packages: "@okta/jwt-verifier": "^2.1.0", "@okta/oidc-middleware": "^4.1.0",
Server code:
import OktaJwtVerifier from '@okta/jwt-verifier';
const oktaJwtVerifier:OktaJwtVerifier = new OktaJwtVerifier(oktaConfig);
...
const jwt = await oktaJwtVerifier.verifyAccessToken(token, audience)
console.log(`JWT: ${JSON.stringify(jwt)}`)
console.log(`IsExpired: ${jwt.isExpired()}`)
Output:
JWT: {"header":{"typ":"JWT","alg":"RS256","kid":"[...]"},"claims":{"ver":1,"jti":"[...]","iss":"[internal uri]","aud":"api://default","iat":1623249209,"exp":1623252809,"cid":"0oa1j3h0l6b5DdVTm1d8","uid":"00u1g2d7eprtOZQrC1d8","scp":["email","profile","openid"],"sub":"me","mail":"[email protected]"}}
ERROR: TypeError: Cannot read property 'exp' of undefined {}
Expected: instead of an error, should see "isExpired: false"
Side question: What happens when I try to verify an expired token? Will verifyAccessToken throw? Do I even need to check the expiration?