/// <summary> /// Flow to perform on successful pick of an account from the WAM popup /// </summary> /// <param name="pi">Details of the WAM provider choosen</param> /// <param name="info">Details of the WAM authenticated account</param> /// <param name="result">WebTokenRequestResult instance containing token info.</param> private async void WAM_Success(WebAccountManager.WebAccountProviderInfo pi, WebAccountManager.WebAccountInfo info, WebTokenRequestResult result) { try { this.ShowBusyStatus(Account.TextAuthenticating, true); // Create an account with the API _cts = new CancellationTokenSource(); using (var api = new ClientApi()) { var response = await api.AuthenticateAsync(info, _cts.Token); // Authenticate the user into the app await this.Platform.AuthManager.SetUserAsync(response); } this.ClearStatus(); this.Platform.Navigation.Home(this.ViewParameter); } catch (Exception ex) { await this.HandleExceptionAsync(ex, "Failed to perform work during WAM success"); } finally { this.Dispose(); } }
protected override async Task <IAuthenticatedUserProfile> GetRefreshAccessToken(CancellationToken ct) { try { using (ClientApi api = new ClientApi()) { return(await api.AuthenticateAsync(this.CurrentUser.AccessToken, ct)); } } catch (Exception ex) { Platform.Current.Logger.LogError(ex, "Could not retrieve refresh token."); return(null); } }
/// <summary> /// Submit the form to the authentication service. /// </summary> /// <returns>Awaitable task is returned.</returns> private async Task SubmitAsync() { try { this.IsSubmitEnabled = false; _cts = new CancellationTokenSource(); this.ShowBusyStatus(Account.TextAuthenticating, true, true); using (var api = new ClientApi()) { string userMessage = null; var response = await api.AuthenticateAsync(this, _cts.Token); // Ensure that there is a valid token returned if (!string.IsNullOrEmpty(response?.AccessToken)) { await this.Platform.AuthManager.SetUserAsync(response); } else { userMessage = Account.TextAuthenticationFailed; } this.ClearStatus(); // Nav home if authenticated else display error message if (this.IsUserAuthenticated) { this.Platform.Navigation.Home(); } else { await this.ShowMessageBoxAsync(_cts.Token, userMessage, this.Title); } } } catch (Exception ex) { await this.HandleExceptionAsync(ex, "Error during account sign-in."); } finally { _cts = null; this.CheckIfValid(); } }