Beispiel #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.");
            }
        }
        private async void AddAccountButton_Click(object sender, RoutedEventArgs e)
        {
            Account account = (Account)((FrameworkElement)sender).DataContext;

            if (account.Provider == localProvider)
            {
                this.NavigationService.Navigate(new Uri("/SetPasswordPage.xaml", UriKind.Relative));
            }
            else
            {
                ExternalLoginResult loginExternalResult = await ExternalLoginManager.GetExternalAccessTokenAsync(account.ProviderUri);

                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)
                    {
                        this.NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
                    }
                    else
                    {
                        ErrorDialog.ShowErrors(result.Errors);
                    }
                }
            }
        }