microsoft-authentication-library-for-android icon indicating copy to clipboard operation
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

Open harishvgk opened this issue 3 years ago • 1 comments

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 avatar Feb 15 '22 05:02 harishvgk

@harishvgk what token expiry configurations do you have in place?

paulokagiri avatar Mar 16 '22 08:03 paulokagiri

No response from the original poster.

negoe avatar Apr 17 '23 21:04 negoe