Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

MsalClientException on calling acquireTokenSilentAsync when Access Token Expired #29

@vinayak214

Description

@vinayak214

I am using 'com.microsoft.identity.client:msal:1.6+' in my Android application with B2C configuration.
It is working as expected when I was trying to login with my credentials and I am also getting my accessToken successfully to use for my server calls.
when i'm calling acquireTokenSilentAsync method to make sure the existing access token is not expired and also to get new token in case of its expiry. The method is returning same token in its call back response AuthenticationResult as long as it is not in expired.
But the problem here is, once the token got expired I am not receiving a new token. Instead receiving an exception saying
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

if (activeAccount != null) {

                mSingleAccountApp.acquireTokenSilentAsync(getScopes(), mAccount.getAuthority( ), getAuthSilentCallback( ));

}
}

/**
 * Callback used in for silent acquireToken calls.
 */
private SilentAuthenticationCallback getAuthSilentCallback() {
    return new SilentAuthenticationCallback( ) {

        @Override
        public void onSuccess(IAuthenticationResult authenticationResult) {
            Log.d(TAG, "Successfully authenticated");
            String silentAccessToken = authenticationResult.getAccessToken( );
            Preferences.setAccessTokens(MicrosoftAzureActivity.this, silentAccessToken);

            Log.d("silentoken", "silent" + silentAccessToken);
            Lunchbox.getInstance( ).callAzureSignUpSignInService(MicrosoftAzureActivity.this, signUpSigInHandler, silentAccessToken);

            /* Successfully got a token, use it to call a protected resource - MSGraph */
            //callGraphAPI(authenticationResult);
        }

        @Override
        public void onError(MsalException exception) {
            final String B2C_PASSWORD_CHANGE = "AADB2C90118";

 **I'm getting the above mentioned error over here Java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $**

            /* Failed to acquireToken */
            displayError(exception);

            if (exception instanceof MsalClientException) {
                /* Exception inside MSAL, more info inside MsalError.java */
            } else if (exception instanceof MsalServiceException) {
                /* Exception when communicating with the STS, likely config issue */
            } else if (exception instanceof MsalUiRequiredException) {
                Log.d("exception", "INTraciton");
                /* Tokens expired or no session, retry with interactive */
            }
        }
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions