Example #1
0
 public void GetAzureADToken(AuthSuccessCallback onAuthCompleted, AuthFailedCallback onAuthFailed)
 {
     this.OnAuthSuccess = onAuthCompleted;
     this.OnAuthFailed  = onAuthFailed;
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
     AccountsSettingsPane.Show();
 }
Example #2
0
        public void LogButton_Tapped(object sender, RoutedEventArgs e)
        {
            AccountsSettingsPane.Show();

            //if (!CustomSettings.IsUserLogged)
            //{
            //    switch ((await KeyCredentialManager.RequestCreateAsync("User", KeyCredentialCreationOption.ReplaceExisting)).Status)
            //    {
            //        case KeyCredentialStatus.Success:
            //            CustomSettings.IsUserLogged = true;
            //            break;

            //        case KeyCredentialStatus.UnknownError:
            //        case KeyCredentialStatus.NotFound:
            //        case KeyCredentialStatus.UserCanceled:
            //        case KeyCredentialStatus.UserPrefersPassword:
            //        case KeyCredentialStatus.CredentialAlreadyExists:
            //        case KeyCredentialStatus.SecurityDeviceLocked:
            //        default:
            //            CustomSettings.IsUserLogged = false;
            //            break;
            //    }
            //}
            //else
            // CustomSettings.IsUserLogged = false;
        }
        private async void SetPasswordButton_Click(object sender, RoutedEventArgs e)
        {
            ResetDisplay();
            SetPassword setPassword = new SetPassword()
            {
                NewPassword     = NewPasswordBox.Password,
                ConfirmPassword = ConfirmPasswordBox.Password
            };

            HttpResult result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.SetPasswordAsync(setPassword);
            }

            if (result.Succeeded)
            {
                AppSettings settings = new AppSettings();
                settings.SavePasswordCredential(this.username, setPassword.NewPassword);
                AccountsSettingsPane.Show();
            }
            else
            {
                DisplayErrors(result.Errors);
            }
            ClearPasswords();
        }
Example #4
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.");
            }
        }
Example #5
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
    public async Task ChooseFromAccountsAsync()
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
    {
#if ENABLE_WINMD_SUPPORT
        //await AccountsSettingsPane.ShowAddAccountAsync();
        AccountsSettingsPane.Show();
#endif
    }
 /// <summary>
 /// Relaunches the AccountsSettingsPane with an error message that the last login attempt failed.
 /// </summary>
 private static void ReportFail()
 {
     AuthError?.Invoke(null, null);
     if (String.IsNullOrEmpty(_paneMessage))
     {
         _paneMessage = "Whoops, something went wrong. Let's try again.\n\n";
     }
     AccountsSettingsPane.Show();
 }
        private void Button_ShowAccountSettings(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;

            rootPage.NotifyUser("Launching AccountSettingsPane", NotifyType.StatusMessage);

            AccountsSettingsPane.Show();

            ((Button)sender).IsEnabled = true;
        }
        private async void SignIn_button_Click(object sender, RoutedEventArgs e)
        {
            OutputPanel.Visibility         = Visibility.Collapsed;
            GetStarted_sp.Visibility       = Visibility.Visible;
            SignInWindows_button.IsEnabled = false;
            AccountsSettingsPane.Show();
            await Task.Delay(1000);

            SignInWindows_button.IsEnabled = true;
        }
 private void Manage_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         AccountsSettingsPane.Show();
     }
     catch (Exception Error) // No stored credentials, so none to delete
     {
         DebugPrint(Error.Message);
     }
 }
Example #10
0
 /// <summary>
 /// Displays the Web Account Manager for users to chose an account to authenticate with.
 /// </summary>
 /// <param name="successHandler">Call back for when an account is successfully choosen by the user.</param>
 /// <param name="failedHandler">Call back for when an error or cancelled UI occurs by the user.</param>
 public void Show(WebAccountManangerSuccessHandler successHandler, WebAccountManangerFailedHandler failedHandler)
 {
     if (this.ShowingUI == false)
     {
         AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
     }
     this.ShowingUI  = true;
     _successHandler = successHandler;
     _failedHandler  = failedHandler;
     AccountsSettingsPane.Show();
 }
Example #11
0
        public void RequestInteractiveSignIn(string[] scopes, string[]?extraScopes = null)
        {
            // Ref for this method and all the related private methods below
            // https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/WebAccountManagement/cs/SingleMicrosoftAccountScenario.xaml.cs
            var pane = AccountsSettingsPane.GetForCurrentView();

            pane.AccountCommandsRequested -= OnAccountCommandsRequested;
            pane.AccountCommandsRequested += OnAccountCommandsRequested;

            AccountsSettingsPane.Show();
        }
Example #12
0
 public async void Login()
 {
     if (await TryGetTokenSilentlyAsync())
     {
         LoginComplete?.Invoke(this, EventArgs.Empty);
         return;
     }
     else
     {
         AccountsSettingsPane.Show();
     }
 }
Example #13
0
 /// <summary>
 /// Logs the user in.
 /// </summary>
 public async void LoginClick()
 {
     if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("IsLoggedIn") &&
         (bool)ApplicationData.Current.RoamingSettings.Values["IsLoggedIn"])
     {
         await LoginAsync();
     }
     else
     {
         AccountsSettingsPane.Show();
     }
 }
        private async void PlaylistsButton_OnClick(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;

            if (_userAccountManager.UserIsSignedIn)
            {
                await MusicContentPaneViewModel.GetPlaylistsAsync();
            }
            else
            {
                AccountsSettingsPane.Show();
            }

            ((Button)sender).IsEnabled = true;
        }
        private async void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;

            if (_userAccountManager.UserIsSignedIn)
            {
                await _userAccountManager.SignOutAccountAsync();
            }
            else
            {
                AccountsSettingsPane.Show();
            }

            ((Button)sender).IsEnabled = true;
        }
Example #16
0
        private async void Session_Click(object sender, RoutedEventArgs e)
        {
            string silentToken = await GetMsaTokenSilentlyAsync();

            if (silentToken != null)
            {
                OdManager.Token = silentToken;
                this.Frame.Navigate(typeof(AnnotatedAudio.View.SessionPicker), OdManager);
            }
            else
            {
                Debug.WriteLine("accountsettingspane show");
                AccountsSettingsPane.Show();
            }
        }
Example #17
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += MainPage_AccountCommandsRequested;
            await DocumentManager.LoadAccountAsync();

            if (DocumentManager.Account != null)
            {
                await DocumentManager.LoadItemsAsync();
            }
            else
            {
                AccountsSettingsPane.Show();
            }
        }
 void CredentialDeletedHandler(CredentialCommand sender)
 {
     try
     {
         // callback invoked when the user requests deletion of the credential in the accounts flyout
         // System will invoke this callback after successfully deleting the credential from the vault
         // do post delete work
         // show accounts settings pane to reflect the new state
         AccountsSettingsPane.Show();
         DebugPrint("Your credential is removed from PasswordVault");
     }
     catch (Exception Error) // No stored credentials, so none to delete
     {
         DebugPrint(Error.Message);
     }
 }
Example #19
0
        private void AccountControl_Click(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;
            // TODO: move the callback registration to OnNavigatedTo
            try
            {
                if (!_isCallbackRegistered)
                {
                    AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
                    _isCallbackRegistered = true;
                }

                DebugPrint("Launching AccountSettingsPane...");
                AccountsSettingsPane.Show();
            }
            catch (Exception ex)
            {
                DebugPrint("AccountControl_Click exception: " + ex.Message);
            }

            ((Button)sender).IsEnabled = true;
        }
Example #20
0
        private async Task <string> GetTokenSilentlyAsync()
        {
            LoggingButton.Content = "Signing";
            string providerId = ApplicationData.Current.LocalSettings.Values[StoredAccountProviderKey]?.ToString();
            string accountId  = ApplicationData.Current.LocalSettings.Values[StoredAccountKey]?.ToString();

            if (null == providerId || null == accountId)
            {
                CustomSettings.IsUserLogged = false;
                return(null);
            }

            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(providerId);

            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountId);

            WebTokenRequest request = new WebTokenRequest(provider, "wl.basic");

            WebTokenRequestResult result = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(request, account);

            if (result.ResponseStatus == WebTokenRequestStatus.UserInteractionRequired)
            {
                CustomSettings.IsUserLogged = false;
                LoggingButton.Content       = "Error";
                AccountsSettingsPane.Show();
                return(null);
            }
            else if (result.ResponseStatus == WebTokenRequestStatus.Success)
            {
                OutputTokenResult(result);
                return(result.ResponseData[0].Token);
            }
            else
            {
                CustomSettings.IsUserLogged = false;
                return(null);
            }
        }
 private void AccountListViewItem_Tapped(object sender, TappedRoutedEventArgs e)
 {
     AccountsSettingsPane.Show();
 }
        // Get an access token for the given context and resourceId. An attempt is first made to
        // acquire the token silently. If that fails, then we start the flow of interacting with the user
        // through.
        private async Task BeginGetAuthTokenAsync()
        {
            string token = null;

            // FindAccountProviderAsync returns the WebAccountProvider of an installed plugin
            // The Provider and Authority specifies the specific plugin
            // This scenario only supports Microsoft accounts.

            // The Microsoft account provider is always present in Windows 10 devices, as is the Azure AD plugin.
            // If a non-installed plugin or incorect identity is specified, FindAccountProviderAsync will return null
            accountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, consumerAuthority);

            // Check if there's a record of the last account used with the app
            var userID = _settings.Values["userID"];

            if (userID != null)
            {
                WebTokenRequest webTokenRequest = new WebTokenRequest(accountProvider, AccountScopeRequested, AccountClientId);

                // Get an account object for the user
                userAccount = await WebAuthenticationCoreManager.FindAccountAsync(accountProvider, (string)userID);


                // Ensure that the saved account works for getting the token we need
                //WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest, userAccount);
                WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(webTokenRequest, userAccount);

                if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success || webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.AccountSwitch)
                {
                    WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
                    userAccount = webTokenResponse.WebAccount;
                    token       = webTokenResponse.Token;
                }
                else
                {
                    // The saved account could not be used for getting a token
                    // Make sure that the UX is ready for a new sign in
                    SignOut();
                }
            }
            else
            {
                // There is no recorded user.
                // Check if a default MSA account has been set already.
                accountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId);

                // Check if the returned authority is "consumers"
                if (accountProvider?.Authority == consumerAuthority)
                {
                    // If it is, then there’s a default MSA account present and there’s no need to show account control
                    WebTokenRequest webTokenRequest = new WebTokenRequest(accountProvider, AccountScopeRequested, AccountClientId);

                    // This is where most of the magic happens.The provider you specified takes over, trying to use the currently
                    // signed in user(or any account saved on the system) to obtain the token you requested without prompting the user.
                    //WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);
                    WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.GetTokenSilentlyAsync(webTokenRequest);

                    if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
                    {
                        WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
                        userAccount = webTokenResponse.WebAccount;
                        token       = webTokenResponse.Token;
                    }
                }
                else
                {
                    // There is no default account or the returned authority is not "consumer", so we must show account control
                    // The AccountCommandsRequested event triggers before the Accounts settings pane is displayed
                    AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
                    AccountsSettingsPane.Show();

                    // Quit at this point - the user interacts with the AccountSettingsPane to enter MSA credentials, so
                    // The OnAuthenticated event gets fired later on to complete this operation
                    return;
                }
            }

            // We succeeded in getting a valid user.
            if (userAccount != null)
            {
                // save user ID in local storage
                _settings.Values["userID"]    = userAccount.Id;
                _settings.Values["userEmail"] = userAccount.UserName;

                OnAuthenticated?.Invoke(this, new AuthenticatedEventArgs(token));
            }

            // We didn't succeed in getting a valid user. Clear the app settings so that another user can sign in.
            else
            {
                SignOut();
                OnAuthenticated?.Invoke(this, new AuthenticatedEventArgs(string.Empty));
            }
        }
Example #23
0
 public void SignIn(Action <Task <UserAccount> > signInStarted)
 {
     signInStartedCallback = signInStarted;
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += BuildAccountsSettingsPaneAsync;
     AccountsSettingsPane.Show();
 }
Example #24
0
 private void SignIn_Click(object sender, RoutedEventArgs e)
 {
     AccountsSettingsPane.Show();
 }
Example #25
0
 public void SignIn()
 {
     AccountsSettingsPane.Show();
 }
Example #26
0
 private void AccountPanel_LoginButtonClick(object sender, RoutedEventArgs e)
 {
     AccountsSettingsPane.Show();
 }
Example #27
0
 private void button_Click(object sender, RoutedEventArgs e)
 {
     // 弹出账号配置界面
     AccountsSettingsPane.Show();
 }
 private void ConnectButton_Click(object sender, RoutedEventArgs e)
 {
     AccountsSettingsPane.Show();
 }
Example #29
0
 public void LogIn()
 {
     AccountsSettingsPane.Show();
 }