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

NetworkErrorException thrown when auth token expired and refresh token was null somehow #1645

Closed
harshitaahuja opened this issue Mar 12, 2018 · 3 comments

Comments

@harshitaahuja
Copy link

harshitaahuja commented Mar 12, 2018

Please fill out the following details:

  1. Version of Mobile SDK Used: 6.0
  2. Issue found in Native App or Hybrid App:Native
  3. OS Version:8.0
  4. Device:Pixel
  5. Steps to reproduce:I left App logged in and unused for 2 days and then opened
  6. Actual behavior: NetworkErrorException is thrown
  7. Expected Behavior:Auth token should get refreshed
  8. Error Log: ClientManager: Exception thrown while getting auth token android.accounts.NetworkErrorException: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at com.salesforce.androidsdk.rest.ClientManager$AccMgrAuthTokenProvider.refreshStaleToken(ClientManager.java:657) at com.salesforce.androidsdk.rest.ClientManager$AccMgrAuthTokenProvider.getNewAuthToken(ClientManager.java:529) at com.salesforce.androidsdk.rest.RestClient$OAuthRefreshInterceptor.refreshAccessToken(RestClient.java:735) at com.salesforce.androidsdk.rest.RestClient$OAuthRefreshInterceptor.intercept(RestClient.java:636) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference at okhttp3.HttpUrl.canonicalize(HttpUrl.java:1751) at okhttp3.FormBody$Builder.add(FormBody.java:121) at com.salesforce.androidsdk.auth.OAuth2.refreshAuthToken(OAuth2.java:338) at com.salesforce.androidsdk.rest.ClientManager$AccMgrAuthTokenProvider.refreshStaleToken(ClientManager.java:619) at com.salesforce.androidsdk.rest.ClientManager$AccMgrAuthTokenProvider.getNewAuthToken(ClientManager.java:529)  at com.salesforce.androidsdk.rest.RestClient$OAuthRefreshInterceptor.refreshAccessToken(RestClient.java:735)  at com.salesforce.androidsdk.rest.RestClient$OAuthRefreshInterceptor.intercept(RestClient.java:636)  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)  at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)  at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)  at java.lang.Thread.run(Thread.java:764) 

I debugged this in OAuth2.java method public static TokenEndpointResponse refreshAuthToken
on line formBodyBuilder.add(REFRESH_TOKEN, refreshToken); exception is thrown, caught by a general catch in ClientManager catch (Exception e) { SalesforceSDKLogger.w(TAG, "Exception thrown while getting new auth token", e); throw new NetworkErrorException(e); }
which is not expected as in this scenario Refresh token should not be null. and even if its is null... user should be logged out as it happens in refresh token expire. What currently user experience is that stuck in the app and getting network error but actually there is no network issue.

Also getting Encryptor: Error during decryption javax.crypto.BadPaddingException: pad block corrupted at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher$BufferedGenericBlockCipher.doFinal(BaseBlockCipher.java:1306) at com.android.org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher.engineDoFinal(BaseBlockCipher.java:1139) at javax.crypto.Cipher.doFinal(Cipher.java:1799) at com.salesforce.androidsdk.analytics.security.Encryptor.decrypt(Encryptor.java:291) at com.salesforce.androidsdk.analytics.security.Encryptor.decrypt(Encryptor.java:154) at com.salesforce.androidsdk.analytics.security.Encryptor.decrypt(Encryptor.java:137) at com.salesforce.androidsdk.app.SalesforceSDKManager.decrypt(SalesforceSDKManager.java:1172) at com.salesforce.androidsdk.rest.ClientManager.peekRestClient(ClientManager.java:164) at com.salesforce.androidsdk.rest.ClientManager.peekRestClient(ClientManager.java:138) at com.salesforce.androidsdk.rest.ClientManager.getRestClient(ClientManager.java:115)

exception randomly.

@bhariharan
Copy link
Contributor

We've fixed most of these issues with Mobile SDK 6.2. Please reopen this issue if you still face issues with a fresh installation of Mobile SDK 6.2.

@ahorobets
Copy link

Hi. Still have this issue in 7.3.0 (version code 66) Android SDK.
An app can't refresh Auth token after some time of idle and throws RefreshTokenRevokedException in refreshAccessToken() method.
Refresh token policy set to "Refresh token is valid until revoked"

@as8703
Copy link

as8703 commented Feb 24, 2022

@harshitaahuja @ArtemGorobets Did you solved this problem? Please help.

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

No branches or pull requests

4 participants