Reputation: 719
As always: Im quite the noob, as you will prob see from the question.
I am playing around with Azure Wams in Xamarin.Android, and it seems to be a great tool. It logs in a user in Xamarin.Android greatly. My problem comes when i want the user to be able to log out and then log in with another account (im using Google for authentication). I used to be able to use it with a log out button, like this:
When logging in the AuthenticationToken is saved in a String for later use. So when the user confirms he wants to log out, i just UserAuth = String.Empty and then i call ConnectToMobileService() again:
public async Task ConnectToMobileService ()
{
try
{
CurrentPlatform.Init ();
client = new MobileServiceClient(
Constants.ApplicationURL,
Constants.ApplicationKey, progressHandler);
if (string.IsNullOrEmpty(UserAuth)) {
await Authenticate();
UserId = user.UserId;
await CreateTables();
await CheckUserId ();
}
else if (!string.IsNullOrEmpty(UserAuth)) {
client.CurrentUser = new MobileServiceUser(UserId);
client.CurrentUser.MobileServiceAuthenticationToken = (UserAuth);
await CreateTables();
}
}
catch (Exception e)
{
CreateAndShowDialog(e, "Error");
}
}
This used to re-launch the authentication-window for me, and the user logged in with hes new account - while the info is saved in preferences for use in other activities and so on. Well, after updating Xamarin and upgrading my license to Indie, this is no longer the case. Now it launces Authenticate for a short second, and then it goes straight back and acts as if the user logged in the exaxt way he did before.
I realize this i probably because there is some sharedpreference saved somewhere for the Wams. Ive studied the methods for clearing these i Java, but i have not been able to recreate them in C#.
client.Logout () does not seem to clear them alone. This is how i tried to recreatet the rest of it:
private void ClearPreferences(){
var prefs = this.GetSharedPreferences("UserDate", 0);
var editor = prefs.Edit ();
editor.Clear ();
editor.Commit ();
}
This does nothing. So, can anyone help me along? How do i reset it, so the users are able to log in with another account - or for example let a friend log in on their phone? Thanks in advance!
Upvotes: 0
Views: 395
Reputation: 719
OK, so it turns out the info is stored as cookies by the auth provider. You have to both log out and clear the cookies. And it then works like a charm. This is how to clear cookies:
client.Logout ();
ClearCookies ();
await ConnectToMobileService ();
}
public static void ClearCookies () {
Android.Webkit.CookieSyncManager.CreateInstance (Android.App.Application.Context);
Android.Webkit.CookieManager.Instance.RemoveAllCookie ();
}
Upvotes: 2