private async void WAM_Success(WebAccountManager.WebAccountProviderInfo pi, WebAccountManager.WebAccountInfo wad, WebTokenRequestResult result) { try { this.ShowBusyStatus(string.Format(Account.TextWebAccountManagerRetrievingProfile, pi.WebAccountType), true); await this.Platform.WebAccountManager.SignoutAsync(); _cts = new CancellationTokenSource(); using (var api = new MicrosoftApi()) { var msa = await api.GetUserProfile(wad.Token, _cts.Token); this.Populate(msa); } } catch (Exception ex) { this.Platform.Logger.LogError(ex, "Failed to perform work during WAM success"); } finally { this.Dispose(); this.ClearStatus(); } }
/// <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(); } }
/// <summary> /// Authenticates a user account returned from the Web Account Manager service. /// </summary> /// <param name="wi">Web account info object instance representing an authenticated WAM user.</param> /// <param name="ct">Cancellation token.</param> /// <returns>Response object from the server.</returns> internal async Task <UserResponse> AuthenticateAsync(WebAccountManager.WebAccountInfo wi, CancellationToken ct) { // This logic below should be server side. Token should be used to retrieve MSA and then check to see if Contoso account exists else register new account. switch (wi.Type) { case WebAccountManager.WebAccountTypes.Microsoft: { // Retrieve MSA profile data MicrosoftAccountDetails msa = null; using (var api = new MicrosoftApi()) { msa = await api.GetUserProfile(wi.Token, ct); } if (msa == null) { throw new Exception("Could not retrieve Microsoft account profile data!"); } var response = await this.IsMicrosoftAccountRegistered(msa.id, ct); if (response != null) { // User account exists, return response return(response); } else { // No account exists, use MSA profile to register user AccountSignUpViewModel vm = new AccountSignUpViewModel(); // Set all the MSA data to the ViewModel vm.Populate(msa); // Call the registration API to create a new account and return return(await this.RegisterAsync(vm, ct)); } } default: throw new NotImplementedException(wi.Type.ToString()); } }