/// <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());
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        /// <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(Services.WebAccountManager.WebAccountProviderInfo pi, Services.WebAccountManager.WebAccountInfo info, WebTokenRequestResult result)
        {
            try
            {
                this.ShowBusyStatus(Strings.Account.TextAuthenticating, true);

                // Create an account with the API
                _cts = new CancellationTokenSource();

                var response = await DataSource.Current.AuthenticateAsync(info, _cts.Token);

                // Authenticate the user into the app
                Platform.Current.AuthManager.SetUser(response);

                Platform.Current.Navigation.Home(this.ViewParameter);
            }
            catch (Exception ex)
            {
                Platform.Current.Logger.LogError(ex, "Failed to perform work during WAM success");
            }
            finally
            {
                this.Dispose();
                this.ClearStatus();
            }
        }