SagePawan
SagePawan

Reputation: 364

How to get refresh token using Microsoft Authentication Library (Msal) in android

I am trying to sign in to my android application using Microsoft Single Sign on, using MSAL implemenation as provided here.

In onCreate

mApp = new PublicClientApplication(this.getApplicationContext(), API.CLIENT_ID, API.AUTHORITY);

When the user presses "Sign in with Microsoft" option, I call the method to acquire token as

mApp.acquireToken(this, getResources().getStringArray(R.array.msal_scopes), getAuthInteractiveCallback());

After handling redirect request in onActivityResult, I grab the authentication response at the callback as

private AuthenticationCallback getAuthInteractiveCallback() {
        return new AuthenticationCallback() {
            @Override
            public void onSuccess(AuthenticationResult authenticationResult) {
                /* Successfully got a token, use it to call a protected resource */
                accessToken = authenticationResult.getAccessToken();
                Log.d("AuthSuccess"," "+accessToken);
            }
            @Override
            public void onError(MsalException exception) {
                /* Failed to acquireToken */

                Log.d("AuthFail"," "+exception.getMessage());

                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 */
                }
            }
            @Override
            public void onCancel() {
                /* User canceled the authentication */
            }
        };
    }

The problem is, AuthenticationResult object gives the access token, but not the refresh token. The object simply does not have refresh token as one of it's parameter. Do I need to further call another method to grab the refresh token as well? How does one get both access and refresh token from microsoft single sign on using MSAL?!

Upvotes: 2

Views: 2061

Answers (1)

Evgeni Roitburg
Evgeni Roitburg

Reputation: 2097

Currently, the library is not exposing the refresh token: https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/202

Upvotes: 1

Related Questions