It is an bug in Xamarin Android that causes the cache tokens not to save.
TokenCachePlugin.cs: Failed to save cache: System.Runtime.Serialization.InvalidDataContractException: No set method for property 'OffsetMinutes' in type 'System.Runtime.Serialization.DateTimeOffsetAdapter'.
This causes the login prompt to appear every time the user uses the app.
This workaround fixed the issue:
I think this due to too aggressive Xamarin.Android linking. This still occurs with Xamarin's cycle 7 release. We faced the same issue and for now have worked around it by adding
in the Android csproj file for the Release configuration.
Waiting for a Xamarin update with a proper fix for this... See https://bugzilla.xamarin.com/show_bug.cgi?id=37491
Here is the code that did not work:
AuthenticationContext authContext = new AuthenticationContext(commonAuthority); if (logout == true) authContext.TokenCache.Clear(); if (authContext.TokenCache.ReadItems().Count() > 0) authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority); authResult = await authContext.AcquireTokenAsync(graphResourceUri, clientId, returnUri, parent); ExternalUniqueId = authResult.UserInfo.UniqueId;