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

Okta refresh token not working. Expired and renew events not triggering #1437

Open
igloo12 opened this issue Jul 23, 2023 · 6 comments
Open
Labels

Comments

@igloo12
Copy link

igloo12 commented Jul 23, 2023

Describe the bug

I am trying to get the refresh token to trigger automatically. I am using okta-auth-js with the okta-react library. I am listening to the token events added, error, expired, renewed. The only event that fires is the added event.

 new OktaAuth({
        services: {
            autoRenew: true,
            autoRemove: true,
            syncStorage: true,
        },
        redirectUri: window.location.origin + '/login/callback'
    })
    oktaAuth.tokenManager.on("added", (key, newToken) => {
        console.log(`token added`)

        if ('accessToken' in newToken) {
            updateToken(newToken.accessToken);
        }
    })

    oktaAuth.tokenManager.on("error", (error: TokenManagerError) => {
        console.log(JSON.stringify(error))
    })
    oktaAuth.tokenManager.on("expired", (key, token) => {
        console.log("Okta token has expired")
    })

    oktaAuth.tokenManager.on("renewed", (key, newToken) => {
        console.log(`renewed token`)
        if ('accessToken' in newToken) {
            updateToken(newToken.accessToken);
        }
    })

Reproduction Steps?

Sign in and wait for the token to expire. No event is triggered

SDK Versions

System:
OS: macOS 13.4.1
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 719.52 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.2.0 - /usr/local/bin/node
npm: 9.6.6 - /usr/local/bin/npm
Browsers:
Chrome: 114.0.5735.198
Safari: 16.5.2
npmPackages:
@okta/okta-react: ^6.7.0 => 6.7.0

Additional Information?

No response

@igloo12 igloo12 added the bug label Jul 23, 2023
@jaredperreault-okta
Copy link
Contributor

What version of @okta/okta-auth-js are you using?

Can you confirm you're only constructing a single oktaAuth instance?

@igloo12
Copy link
Author

igloo12 commented Jul 24, 2023

I am only constructing one instance of oktaAuth.

I was using the prepacked okta-js version in okta-react 7.0.0 but I have tried with the latest 7.3.1 too and it doesn't work

@shuowu-okta
Copy link
Contributor

@igloo12 Can you share more information about how you observe token expiration happen? You can use expireearlyseconds config to observe token expiration (DEV mode only).

Internal Ref: OKTA-631863

@igloo12
Copy link
Author

igloo12 commented Jul 26, 2023

@shuowu-okta It seems the issue is when the App is background. When I set the expireearlyseconds I see the token refresh as expected. But if I leave the app minimized and come back later the events don't fire and the token is expired

@fseee
Copy link

fseee commented Oct 4, 2023

We faced similar issue, since it seems that browser puts background/inactive tabs in a sleep mode after certain time.
We solved it by using a dummy webworker which keeps active the tab.

@pream1234
Copy link

We are facing the similar issue, token auto renew is not happening when the user minimize the tab. Also the when user stays in same path its not getting renewed. is there any fix for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants