Okta Auth JS SDK TokenManager not refreshing token

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. 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. 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]);

          customHashFragment: keyValuePair,
          disableOAuth2StateCheck: true
        console.log('Login: \n');

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

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! :slight_smile:


1 Like


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