I'm using Xamarin.Auth to authenticate with services like foursquare and so. I've gotten my authentication code working all good, the problem is that the account data is not persisted when I deploy a new version of my app - each time I deploy a test version on the phone, I've to re-authenticate.
Here's how I store the account;
/// <summary>
/// Stores the account.
/// </summary>
private void StoreAccount(AuthenticatorCompletedEventArgs eventArgs)
{
if (!eventArgs.IsAuthenticated) // make sure we are authenticated.
{
Log.Debug(Logging.AppTag, "FourSquareClient can't store account as auth. is cancelled. ");
return;
}
this.IsAuthenticated = true;
this.Account = eventArgs.Account;
AccountStore.Create(this.OwnerContext).Save(eventArgs.Account, "Foursquare");
}
and here is how I check if we have a stored account;
/// <summary>
/// Retrieves stored account.
/// </summary>
private void RetrieveAccount()
{
if (this.IsAuthenticated)
{
Log.Debug(Logging.AppTag, "FourSquareClient is already authenticated! ");
return;
}
var accounts = AccountStore.Create(this.OwnerContext).FindAccountsForService("Foursquare");
var enumerable = accounts as IList<Account> ?? accounts.ToList();
if (enumerable.Any())
{
Log.Info(Logging.AppTag, "Foursquareclient found account data.");
this.IsAuthenticated = true;
this.Account = enumerable.First();
}
else
{
Log.Info(Logging.AppTag, "Foursquareclient no account data found!");
this.IsAuthenticated = false;
this.Account = null;
}
}