Removed Account reappears after application restart
See original GitHub issue(Not sure if there is a bug in MSAL, a glitch on my Android device, or a bug in my code)
On Android, Is there a manual way of clearing all accounts at the OS level? I seem to have got an Account that is “stuck” in the cache on my testing device.
I’m using the standard pattern from the samples: I call PCA.GetAccounts()
, and if there is only one account, I attempt to use that with PCA.AcquireTokenSilent()
. If I catch a MsalUiRequiredException
, I try again with PCA.AcquireTokenInteractive()
. To log the user out, I make a call to PCA.RemoveAsync()
with the logged in Account.
Given two users, “User1@company.com” and “User2@company.com”. User1 is my account, that I normally test and debug with. This all works fine with account User1. After logging out and restarting the app, User1 is not returned from the call PCA.GetAccounts()
.
Here’s the problem: At some point, I used another account (User2) to log on, as I wanted to test it with more than one account. Now User2 is always returned in the call from PCA.GetAccounts()
. If I call PCA.GetAccounts()
before restarting the app, User2 is gone. But when I restart the app, it’s back. Doing the same method with User1 works perfectly: if I log out User1, it is gone until I acquire a token for it again. It also works perfectly on UWP. I have not tested iOS.
This is a corporate app and all my users have orders not to share passwords or phones, so it’s not a huge problem yet. But I’d really like to know what to do if this happens to one of their devices, and it would be nice to clear my testing device. This problem causes the app to log on with the wrong Account
when all other accounts have been logged out.
What I’ve tried:
- Logged on as User2 again, and log out
- Restarted the device
- Cleared all users via RemoveAsync()
- Uninstalled Brave browser
- Cleared history/cookies of all installed browsers (System browser - simply called “Internet”, Chrome, FireFox)
- Used calls to ISharedPreferencesEditor to clear all preferences listed in
AndroidTokenCacheAccessor
:AccessTokenSharedPreferenceName
,RefreshTokenSharedPreferenceName
,IdTokenSharedPreferenceName
, andAccountSharedPreferenceName
. These Shared Preferences disappear, then when I restart the app, they are back.
Particulars:
- Microsoft.Identify.Client 3.0.8, from Nuget, and later built from latest source, 6e60685c88ebf60ce805e58c2b549444870b70be (Updated to latest because I was having the problem with I think 3.0.1-preview)
- Android 9 Device (Galaxy Note 9)
- Kernel: 4.9.112-15119493
- Build PPR1.180610.011.N960USQS1CSD1
- Visual Studio 2017, 15.9.11
- Target Android Version 9.0 (API Level 28 - Pie)
- Minimum Android Version 6.0 (API level 23 - Marshmallow)
- Xamarin.Forms 4.0.0.425677
- Xamarin.Android.* 28.0.0.1
- Using Azure AD accounts, sync’d to our domain with Azure AD Connect
If you need any more info, I’m happy to provide it.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top GitHub Comments
@jennyf19 Oops, I forgot to capture logs during the
RemoveAsync()
call. Here they are:Have a great weekend!
@jennyf19 Thanks for the response.
I completely forgot I had debug logging on. There is voluminous amounts of Android logging going on so I don’t have MSAL logs by themselves at the moment, but here are all the lines with “MSAL” in them. (I can add the logging code to isolate the MSAL logs if neccessary - let me know.):
Here is the code for creating the PCA:
The code for acquiring a token follows. Note that
WithUseEmbeddedWebView(true)
was added in trying to work this problem - didn’t seem to make a difference. Also,_msalUiWrapper.MsalUIObject
contains a reference to myMainActivity
(Xamarin.Forms.Platform.Android.FormsAppCompatActivity
) on Android, or myWindow.Current
(Windows.UI.Xaml.Window
) on UWP. It contains null on iOS (which may be a problem later but I’m not testing on iOS yet).Here’s the code for signing out: