MSAL ANDROID : MultiAccountMode issue with Logout

Prakash, Tinju 6 Reputation points
2022-12-12T12:08:41.55+00:00

We are facing issues to logout from Android application after login. While logout, it displays a screen where the already logged in email displays, tapping on that allows the user to login to the application with out a password. The application is configured as MultiAccount mode. Below is the code for logout.
removeAccountButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mMultipleAccountApp == null) {
return;
}

            /**  
             * Removes the selected account and cached tokens from this app (or device, if the device is in shared mode).  
             */  
            mMultipleAccountApp.removeAccount(accountList.get(accountListSpinner.getSelectedItemPosition()),  
                    new IMultipleAccountPublicClientApplication.RemoveAccountCallback() {  
                        @Override  
                        public void onRemoved() {  
                            Toast.makeText(getContext(), "Account removed.", Toast.LENGTH_SHORT)  
                                    .show();  

                            /* Reload account asynchronously to get the up-to-date list. */  
                            loadAccounts();  
                        }  

                        @Override  
                        public void onError(@NonNull MsalException exception) {  
                            displayError(exception);  
                        }  
                    });  
        }  
    });
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2022-12-14T07:56:09.127+00:00

    Hi @Prakash, Tinju ,

    Thanks for reaching out.

    From your query, I understand you are looking to prompt the user to enter the credentials to login into Android application.

    Generally, you can achieve this by clearing the cache but in android we can't clear the cookies.

    If your app is configured to use a broker, then only tokens associated with your client are removed but account won't be removed using removeAccount().

    To prompt the user for credentials, you need to prompt the user by calling AcquireTokenInteractive().

    Hope this will help.

    Thanks,
    Shweta

    -----------------------------------------

    Please remember to "Accept Answer" if answer helped you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.