private async void WAM_Success(Services.WebAccountManager.WebAccountProviderInfo pi, Services.WebAccountManager.WebAccountInfo wad, WebTokenRequestResult result) { try { this.ShowBusyStatus(string.Format(Strings.Account.TextWebAccountManagerRetrievingProfile, pi.WebAccountType), true); await Platform.Current.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) { Platform.Current.Logger.LogError(ex, "Failed to perform work during WAM success"); } finally { this.Dispose(); this.ClearStatus(); } }
/// <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> public async Task <UserResponse> AuthenticateAsync(Services.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 MediaAppSample account exists else register new account. switch (wi.Type) { case Services.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()); } }