# Okta Auth JS SDK TokenManager not refreshing token

**URL:** <https://devforum.okta.com/t/okta-auth-js-sdk-tokenmanager-not-refreshing-token/2001>\
**Category:** OAuth/OIDC\
**Created:** [June 19, 2018, 4:15pm UTC](https://devforum.okta.com/t/okta-auth-js-sdk-tokenmanager-not-refreshing-token/2001 "2018-06-19T16:15:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scollins](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/scollins/32/542_2.png) [@scollins](https://devforum.okta.com/u/scollins)\
**Post date:** [June 19, 2018, 4:15pm UTC](https://devforum.okta.com/t/okta-auth-js-sdk-tokenmanager-not-refreshing-token/2001/1 "2018-06-19T16:15:28Z")

</div>

Hello everyone. I am currently working on an Ionic app that I kickstarted from a post that @mraible posted on the Okta developer blog [here](https://developer.okta.com/blog/2017/08/22/build-an-ionic-app-with-user-authentication). The authentication handshake is working and users can log into the application without issue, but we are hitting the 1 hour OIDC timeout. I am looking to make use of the TokenManager to refresh a user’s session automatically as per the documentation [here](https://github.com/okta/okta-auth-js#tokenmanageraddkey-token). Below is the snippet of code that I am using:

```
login() {
this.oauthService.createAndSaveNonce().then(nonce => {
  const authClient = new OktaAuth({
    clientId: this.oauthService.clientId,
    redirectUri: this.oauthService.redirectUri,
    url: 'https://[our-tenant].oktapreview.com',
    issuer: 'default'
  });
  return authClient.signIn({
    username: this.username,
    password: this.password
  }).then((response) => {
    if (response.status === 'SUCCESS') {
      return authClient.token.getWithoutPrompt({
        nonce: nonce,
        responseType: ['id_token', 'token'],
        sessionToken: response.sessionToken,
        scopes: this.oauthService.scope.split(' ')
      }).then((tokens) => {
        const idToken = tokens[0].idToken;
        const accessToken = tokens[1].accessToken;
        const keyValuePair = `#id_token=${encodeURIComponent(idToken)}&access_token=${encodeURIComponent(accessToken)}`;
        
        // This is the portion where I add the tokens to TokenManager
        authClient.tokenManager.add('okta_id_token', tokens[0]);
        authClient.tokenManager.add('okta_access_token', tokens[1]);

        this.oauthService.tryLogin({
          customHashFragment: keyValuePair,
          disableOAuth2StateCheck: true
        });
        console.log('Login: \n');
        console.log(tokens[0]);

        this.navCtrl.setRoot(HomePage);
      });
    } else {
      throw new Error('We cannot handle the ' + response.status + ' status');
    }
  }).fail((error) => {
    console.error(error);
    let errorAlert = this.alertCtrl.create({
      title: 'Error',
      subTitle: error.message,
      buttons: ['Retry']
    });
    errorAlert.present();
  });
});
}

```

I am logging out the id\_token response here and then attempting to access it in my Home page with tokenManager.get(‘okta\_id\_token’) and that is returning the same value. That leads me to believe that it is adding the token the the TokenManger properly, but it is simply not refreshing it.

Any guidance you could provide would be much appreciated! 🙂

-Sean

---

<div class="post-metadata">

**Author:** ![mao](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@mao](https://devforum.okta.com/u/mao)\
**Post date:** [January 22, 2019, 11:47pm UTC](https://devforum.okta.com/t/okta-auth-js-sdk-tokenmanager-not-refreshing-token/2001/2 "2019-01-22T23:47:31Z")

</div>

Sean,

Have you got this working? If so, do you mind share the solution?

Thanks  
Mao

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [January 23, 2024, 7:03pm UTC](https://devforum.okta.com/t/okta-auth-js-sdk-tokenmanager-not-refreshing-token/2001/3 "2024-01-23T19:03:12Z")

</div>


