okta / okta-auth-js

The official js wrapper around Okta's auth API
Other
453 stars 265 forks source link

In Cypress, OktaAuth() is returning a JWT token with an 'issued time' time of 1 hour ago and expiry time of now #1397

Open mohammad-shafi-mck opened 1 year ago

mohammad-shafi-mck commented 1 year ago

Describe the bug?

In Cypress, OktaAuth() is returning a JWT token with an 'issued time' time of 1 hour ago and expiry time of now.

In a cypress suite using okta-auth-js to log in via the API, The JWT token expires as soon as it is created, so any following api requests via Okta return a 4XX and the user is logged out, causing tests to fail.

*This may be unrelated but, this bug began when the British time zone changed from time change from GMT(UTC) to BST(UTC+1)

What is expected to happen?

A JWT token with an 'issued time' of now and an 'expiry time' of now + 1 hour.

What is the actual behavior?

In Cypress, OktaAuth() is returning a JWT token with an 'issued time' time of 1 hour ago and expiry time of now.

Reproduction Steps?

SDK Versions

"okta": "^1.0.0" "@okta/okta-auth-js": "^6.8.0"

Execution Environment

node v18.6.0 Chrome Version 112.0.5615.49

Additional Information?

No response

shuowu-okta commented 1 year ago

@mohammad-shafi-mck okta-auth-js uses Date.now() to calculate the expiresAt field in the token, which means the time you see from the token will be in UTC(timezone agnostic). I think the issue most probably locate in the api token validation part.

You can also follow the expires_in field from the decoded token, the token should still be active if the number is positive.