public static async Task <bool> SwitchToAccount(Account account) { if (account != null && account.UserId != null) { AuthStorageHelper.SavePinTimer(); AuthStorageHelper.GetAuthStorageHelper().PersistCredentials(account); RestClient client = SDKManager.GlobalClientManager.PeekRestClient(); if (client != null) { OAuth2.ClearCookies(account.GetLoginOptions()); IdentityResponse identity = await OAuth2.CallIdentityService(account.IdentityUrl, client); if (identity != null) { account.UserId = identity.UserId; account.UserName = identity.UserName; account.Policy = identity.MobilePolicy; AuthStorageHelper.GetAuthStorageHelper().PersistCredentials(account); } OAuth2.RefreshCookies(); PlatformAdapter.SendToCustomLogger("AccountManager.SwitchToAccount - done, result = true", LoggingLevel.Verbose); return(true); } } PlatformAdapter.SendToCustomLogger("AccountManager.SwitchToAccount - done, result = false", LoggingLevel.Verbose); return(false); }
public static async Task <bool> SwitchToAccountAsync(Account newAccount, CancellationToken cancellationToken = default(CancellationToken)) { var oldAccount = LoggedInAccount; if (newAccount?.UserId != null) { // save current user pin timer AuthStorageHelper.SavePinTimer(); await AuthStorageHelper.PersistCurrentAccountAsync(newAccount); var client = SDKManager.GlobalClientManager.PeekRestClient(); if (client != null) { await AuthStorageHelper.ClearCookiesAsync(newAccount.GetLoginOptions()); var identity = await OAuth2.CallIdentityServiceAsync(newAccount.IdentityUrl, client, cancellationToken); if (identity != null) { newAccount.UserId = identity.UserId; newAccount.UserName = identity.UserName; newAccount.Policy = identity.MobilePolicy; await AuthStorageHelper.PersistCurrentAccountAsync(newAccount); } AuthStorageHelper.RefreshCookies(); LoggingService.Log("switched accounts, result = true", LoggingLevel.Verbose); return(true); } // log new user in LoggedInAccount = newAccount; RaiseAuthenticatedAccountChangedEvent(oldAccount, newAccount); } LoggingService.Log("switched accounts, result = false", LoggingLevel.Verbose); return(false); }
public static void SavePinTimer() { AuthStorageHelper.SavePinTimer(); }