okta/okta-react-native

Okta throws error on refresh token after 24 hours or every morning since July 7th 2023

somasekharkakarla opened this issue · 12 comments

Describe the bug?

i configured createConfig in my index file. on every reopen of app i am refreshing the token. On every morning i face the issue from okta i.e Okta client isn't configured . but i goes off when i re-install it. if my config way is wrong it should come on every reopen of the app. it is happening only on morning. i think when token has expired or when the day changes. This was a big issue even my old apps all my user got the same issue at once. i think it not due to the lib update. Please make it a priority and resolve this.
This is observed since July 7th 2023 before it is fine. i didn't change my okta lib from jan 2023

I have class called OktaConfiguration

OktaConfiguration looks like

const OktaConfiguration = async (isDebug: boolean) => {
const uriPackages = OKTA_PACKAGE_NAME;
const uriCallback = uriPackages + ':/callback';
const redirectUriCallback = uriPackages + ':/logout';
console.log('createConfig inside OktaConfiguration');
return await createConfig({
clientId: isDebug ? OKTA_STAGE_KEY : OKTA_PROD_KEY,
redirectUri: uriCallback,
discoveryUri: isDebug
? OKTA_DISCOVERY_STAGE_URI
: OKTA_DISCOVERY_PROD_URI,
endSessionRedirectUri: redirectUriCallback,
scopes: ['openid', 'profile', 'offline_access'],
requireHardwareBackedKeyStore: false, // Optional
androidChromeTabColor: '#FF00AA', // Optional
});
};

export default OktaConfiguration;
In Index.js i am call it has

OktaConfiguration(isDebug)
.then(result => console.log('OktaConfiguration >> result', result))
.catch(err => {
console.log('OktaConfiguration >> error', err);
});

see the the logs
i highlighted with red dots.

Screenshot 2023-07-27 at 10 50 39 AM

What is expected to happen?

it should refresh the token

What is the actual behavior?

it is trowing error

Reproduction Steps?

use lib and refresh the app after a day

Additional Information?

No response

SDK Version

"@okta/okta-react-native": "^2.7.0",

Build Information

No response

Hi @somasekharkakarla, thanks for filing this bug. I think your configuration is fine. The error message is likely misleading. Could you describe how you're logging in your user? Is it using browser login or custom login?

HI @rajdeepnanua-okta i am using custom login

 loginThroughOkta = async (email: string, password: string) => {
    try {
      return await signIn({ username: email, password: password })
        .then(async response => {
          this.logWarns('Direct-login', response.access_token);
          return response.access_token;
        })
        .catch(err => {
          this.throwErrors(err, 'Error on Keychain Addition or Login Error');
        });
    } catch (err) {
      this.throwErrors(err, 'Error on Keychain Addition or Login Error');
    }
  };

This is how i am getting my refresh token

addRefreshToken = async (): Promise<string | null | undefined> => {
    const isNetwork = await netInfoUtils.fetch();
    if (isNetwork.isInternetReachable) {
      return await refreshTokens()
        .then(async response => {
          this.logWarns('addRefreshToken', response.access_token);
          return response.access_token;
        })
        .catch(async err => {
        });
    } else {
    }
  };

Error is

isNetwork {"details": {"carrier": "T-Mobile", "cellularGeneration": "3g", "isConnectionExpensive": true}, "isConnected": true, "isInternetReachable": true, "isWifiEnabled": false, "type": "cellular"}
 LOG  addRefreshToken Err [Error: OktaOidc client isn't configured, check if you have created a configuration with createConfig]

Hi @rajdeepnanua-okta, Please look into this

Hi @rajdeepnanua-okta , recently i checked refreshTokens() itself is not working. even after immediate login

i think i found the solution

In Android > OktaSdkBridgeModule.java at public void refreshTokens(final Promise promise){}

@ReactMethod
    public void refreshTokens(final Promise promise) {
        try {
             sessionClient = authClient.getSessionClient(); //  >>>> added it
            if (sessionClient == null) {
                promise.reject(OktaSdkError.NOT_CONFIGURED.getErrorCode(), OktaSdkError.NOT_CONFIGURED.getErrorMessage());
                return;
            }

            sessionClient.refreshToken(new RequestCallback<Tokens, AuthorizationException>() {
                @Override
                public void onSuccess(@NonNull Tokens result) {
                    WritableMap params = Arguments.createMap();
                    params.putString(OktaSdkConstant.ACCESS_TOKEN_KEY, result.getAccessToken());
                    params.putString(OktaSdkConstant.ID_TOKEN_KEY, result.getIdToken());
                    params.putString(OktaSdkConstant.REFRESH_TOKEN_KEY, result.getRefreshToken());
                    promise.resolve(params);
                }

                @Override
                public void onError(String e, AuthorizationException error) {
                    promise.reject(OktaSdkError.OKTA_OIDC_ERROR.getErrorCode(), error.getLocalizedMessage(), error);
                }
            });
        } catch (Error e) {
            promise.reject(OktaSdkError.OKTA_OIDC_ERROR.getErrorCode(), e.getLocalizedMessage(), e);
        }
    }

add this sessionClient = authClient.getSessionClient(); at start of the function it is working now.

it is due to sessionClient is null.
Hi @rajdeepnanua-okta can please verify it

Hi @somasekharkakarla, thanks for the find. Yes, that does seem like the root cause of the issue. I am working on a fix for this issue.

it is due to sessionClient is null.

This doesn't work for me 😐

Hi @rajdeepnanua-okta any update on this. we are facing too many tickets from our clients.

Hi @rajdeepnanua-okta any update on this. we are facing too many tickets from our clients.

downgrading to 2.8.0 works for me, try this once @somasekharkakarla

Hi @bharathmsd7 , Thank you for comment. But latest version is 2.8.0. Are you saying to upgrade?

Hi @bharathmsd7 , Thank you for comment. But latest version is 2.8.0. Are you saying to upgrade?

Latest version according to npm is 2.9.0 where this bug got originated.

Using older version <2.9.0 by removing ^ from "@okta/okta-react-native": "^2.7.0", will fix the issue

@okta/okta-react-native": "2.8.0
This worked for me

Hi @somasekharkakarla, the issue should be fixed in 2.9.1. Let me know if you still run into the issue with that release. Feel free to reopen the issue in that case.