Esempio n. 1
0
        private async void WebAccountProviderInvokedHandler(WebAccountProviderCommand command)
        {
            string externalLoginUri = command.WebAccountProvider.Id;
            ExternalLoginResult loginExternalResult = await ExternalLoginManager.GetExternalAccessTokenAsync(externalLoginUri);

            string accessToken = loginExternalResult.AccessToken;

            if (accessToken != null)
            {
                HttpResult result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.AddExternalLoginAsync(new AddExternalLogin()
                    {
                        ExternalAccessToken = accessToken
                    });
                }
                if (result.Succeeded)
                {
                    AccountsSettingsPane.Show();
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
            else
            {
                await ErrorDialog.ShowErrorAsync("Failed to connect to external account.");
            }
        }
Esempio n. 2
0
        private async void SignUpButton_Click(object sender, RoutedEventArgs e)
        {
            ClearErrors();

            RegisterExternalUser registerExternalUser = new RegisterExternalUser()
            {
                UserName = this.UsernameTextBox.Text,
            };

            HttpResult result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.RegisterExternalAsync(registerExternalUser);
            }
            if (result.Succeeded)
            {
                // Need to login again now that we are registered - should happen with the existing cookie
                ExternalLoginResult externalLoginResult = await ExternalLoginManager.GetExternalAccessTokenAsync(externalLoginUri, silentMode : true);

                if (externalLoginResult.AccessToken != null)
                {
                    bool completed = accessTokenSource.TrySetResult(externalLoginResult.AccessToken);
                    this.Frame.Navigate(typeof(TodoPage));
                }
                else
                {
                    await ErrorDialog.ShowErrorAsync("Failed to register external account");
                }
            }
            else
            {
                DisplayErrors(result.Errors);
            }
        }
Esempio n. 3
0
        private async void WebAccountProviderInvokedHandler(WebAccountProviderCommand command)
        {
            string externalLoginUri = command.WebAccountProvider.Id;
            ExternalLoginResult loginExternalResult = await ExternalLoginManager.GetExternalAccessTokenAsync(externalLoginUri);

            if (loginExternalResult.AccessToken != null)
            {
                // Save the access token so we can check if the user has registered
                AppSettings settings = new AppSettings();
                settings.AccessToken = loginExternalResult.AccessToken;

                HttpResult <UserInfo> result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.GetUserInfoAsync();
                }
                if (result.Succeeded)
                {
                    if (result.Content.HasRegistered)
                    {
                        accessTokenSource.TrySetResult(loginExternalResult.AccessToken);
                        this.Frame.GoBack();
                    }
                    else
                    {
                        RegisterExternalPageParameters parameters = new RegisterExternalPageParameters()
                        {
                            AccessTokenSource = accessTokenSource,
                            ExternalLoginUri  = externalLoginUri,
                            UserInfo          = result.Content
                        };
                        this.Frame.Navigate(typeof(RegisterExternalPage), parameters);
                    }
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync("Failed to connected to external account.", result.Errors);
                }
            }
            else
            {
                await ErrorDialog.ShowErrorAsync("Failed to connected to external account.");
            }
        }