internal void Populate(MicrosoftAccountDetails msa) { if (msa == null) { return; } this.FirstName = msa.first_name; this.LastName = msa.last_name; this.Username = msa.emails.account; this.Address1 = msa.addresses?.personal?.street; this.Address2 = msa.addresses?.personal?.street_2?.ToString(); this.City = msa.addresses?.personal?.city; this.State = msa.addresses?.personal?.state; this.PostalCode = msa.addresses?.personal?.postal_code; this.DOB = new DateTime(msa.birth_year, msa.birth_month, msa.birth_day); }
/// <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()); } }