-
Notifications
You must be signed in to change notification settings - Fork 19
MsalClientException on calling acquireTokenSilentAsync when Access Token Expired #29
Description
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 */
}
}
};
}