microsoft-authentication-library-for-android
microsoft-authentication-library-for-android copied to clipboard
Aquire Token Silently - Exception thrown - Attempt to invoke virtual method 'void com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse.setStatusCode(int)' on a null object reference
Getting this exception on calling acquireTokenSilentAsync, after 1 hour of login:- silent token error :: com.microsoft.identity.client.exception.MsalClientException: Attempt to invoke virtual method 'void com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse.setStatusCode(int)' on a null object reference
Calling the same method acquireTokenSilentAsync in multiple scenarios, but till 1 hour the method does not throw this exception and works fine.
-
Devices - All Android phones & emulators
-
MSAL Version - in Gradle, implementation ("com.microsoft.identity.client:msal:2.+")
Stacktrace silent token error :: com.microsoft.identity.client.exception.MsalClientException: Attempt to invoke virtual method 'void com.microsoft.identity.common.internal.providers.oauth2.TokenErrorResponse.setStatusCode(int)' on a null object reference
Code
public void acquireTokenSilently (Promise promise){
try {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(reactAppContext);
String accountIdentifier = preferences.getString(ACCOUNT_IDENTIFIER, "");
System.out.println("account Identifier is"+accountIdentifier);
IAccount account = publicClientApplication.getAccount(accountIdentifier);
AcquireTokenSilentParameters.Builder acquireTokenSilentParameters =
new AcquireTokenSilentParameters.Builder()
.forAccount(account)
.withScopes(Arrays.asList(SCOPE_URL));
String authority =
publicClientApplication
.getConfiguration()
.getDefaultAuthority()
.getAuthorityURL()
.toString();
System.out.println("authority url is"+authority);
acquireTokenSilentParameters.fromAuthority(authority);
acquireTokenSilentParameters.withCallback(getAuthSilentCallback(promise));
publicClientApplication.acquireTokenSilentAsync(acquireTokenSilentParameters.build());
} catch (Exception e) {
promise.reject(e);
}
}
Please help us to fix this issue. We have an app release soon with MSAL. Thanks in Advance!
@harishvgk what token expiry configurations do you have in place?
No response from the original poster.