private async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs) { AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral(); HttpResult <ExternalLogin[]> result; using (AccountClient accountClient = ClientFactory.CreateAccountClient()) { result = await accountClient.GetExternalLoginsAsync(); } if (result.Succeeded) { eventArgs.HeaderText = "Please select a login provider."; WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler); foreach (ExternalLogin externalLogin in result.Content) { WebAccountProvider provider = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]); WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCmdHandler); eventArgs.WebAccountProviderCommands.Add(providerCommand); } } else { await ErrorDialog.ShowErrorsAsync("Error connecting to external accounts.", result.Errors); } deferral.Complete(); }
// This event handler is called when the Account settings pane is to be launched. private async void OnAccountCommandsRequested( AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); // This scenario only lets the user have one account at a time. // If there already is an account, we do not include a provider in the list // This will prevent the add account button from showing up. bool isPresent = ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey); if (isPresent) { await AddWebAccount(e); } else { await AddWebAccountProvider(e); } AddLinksAndDescription(e); deferral.Complete(); }
private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); if (_userId == null) { // 弹出账号配置界面用于账号登录 await ShowLoginUI(e); // 弹出界面上需要显示的标题文字 e.HeaderText = "请登录"; } else { // 弹出账号配置界面用于账号管理(本例用于演示注销) await ShowLogoutUI(e); // 弹出界面上需要显示的标题文字 e.HeaderText = "请注销"; } // 在弹出界面上添加自定义按钮 e.Commands.Add(new SettingsCommand("help", "帮助", HelpInvoked)); e.Commands.Add(new SettingsCommand("about", "关于", AboutInvoked)); deferral.Complete(); }
private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(await MicrosoftAccount.GetProvider(), WebAccountProviderCommandInvoked); e.WebAccountProviderCommands.Add(providerCommand); deferral.Complete(); }
private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args) { AccountsSettingsPaneEventDeferral deferral = args.GetDeferral(); await AddWebAccountProvider(args); AddLinksAndDescription(args); deferral.Complete(); }
#pragma warning disable VSTHRD100 // Avoid async void methods private async void Authenticator_AccountCommandsRequested( #pragma warning restore VSTHRD100 // Avoid async void methods AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args) { AccountsSettingsPaneEventDeferral deferral = null; try { deferral = args.GetDeferral(); if (!string.IsNullOrEmpty(_optionalHeaderText)) { args.HeaderText = _optionalHeaderText; } if (string.Equals("common", _authority.TenantId)) { _logger.Verbose("Displaying selector for common"); await AddSelectorsAsync( args, addOrgAccounts : true, addMsaAccounts : true).ConfigureAwait(true); } else if (string.Equals("organizations", _authority.TenantId)) { _logger.Verbose("Displaying selector for organizations"); await AddSelectorsAsync( args, addOrgAccounts : true, addMsaAccounts : _isMsaPassthrough).ConfigureAwait(true); } else if (string.Equals("consumers", _authority.TenantId)) { _logger.Verbose("Displaying selector for consumers"); await AddSelectorsAsync( args, addOrgAccounts : false, addMsaAccounts : true).ConfigureAwait(true); } else { _logger.Verbose("Displaying selector for tenanted authority"); await AddSelectorsAsync( args, addOrgAccounts : true, addMsaAccounts : _isMsaPassthrough, tenantId : _authority.AuthorityInfo.CanonicalAuthority).ConfigureAwait(true); } } finally { deferral?.Complete(); } }
private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(ProviderId, Authority); WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked); e.WebAccountProviderCommands.Add(providerCommand); deferral.Complete(); }
private async Task <WebTokenRequestResult> SignInAsync(string resource) { var taskCompletionSource = new TaskCompletionSource <WebTokenRequestResult>(); TypedEventHandler <AccountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs> AccountCommandsRequestedHandler = null; AccountCommandsRequestedHandler = async(s, e) => { Debug.WriteLine("AccountCommandsRequestedHandler"); AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= AccountCommandsRequestedHandler; // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); if (deferral != null) { // The Microsoft account provider is always present in Windows 10 devices, even IoT Core, as is the Azure AD plugin. var providerCommand = new WebAccountProviderCommand(await GetProvider(), async(command) => { Debug.WriteLine("WebAccountProviderCommandInvokedHandler"); try { WebTokenRequest wtr = new WebTokenRequest(command.WebAccountProvider, _scope, _clientId); if (resource != null) { wtr.Properties.Add("resource", resource); } var wtrr = await RequestTokenWithTimeout(wtr); SaveToken(wtrr, resource); taskCompletionSource.SetResult(wtrr); } catch (Exception ex) { ServiceUtil.LogService.Write("Web Token Request Error: " + ex.Message, LoggingLevel.Error); taskCompletionSource.SetResult(null); } }); e.WebAccountProviderCommands.Add(providerCommand); deferral.Complete(); } }; AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += AccountCommandsRequestedHandler; await AccountsSettingsPane.ShowAddAccountAsync(); return(await taskCompletionSource.Task); }
private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); try { foreach (var pi in _providers) { // This scenario only lets the user have one account at a time. // If there already is an account, we do not include a provider in the list // This will prevent the add account button from showing up. if (this.HasWebAccountInfo(pi.WebAccountType)) { WebAccount account = await this.GetWebAccount(pi.WebAccountType); if (account != null) { WebAccountCommand command = new WebAccountCommand(account, OnWebAccountRequested, pi.Actions); e.WebAccountCommands.Add(command); } } else { var provider = await this.GetProvider(pi.ProviderID, pi.Authority); if (provider != null) { WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, OnWebAccountProviderRequested); e.WebAccountProviderCommands.Add(providerCommand); } } } e.HeaderText = string.Format(Strings.Account.TextWebAccountManagerSignUpDescription, PlatformBase.CurrentCore.AppInfo.AppName); // You can add links such as privacy policy, help, general account settings e.Commands.Add(new SettingsCommand("privacypolicy", Strings.Resources.ViewTitlePrivacyPolicy, (c) => { PlatformBase.CurrentCore.NavigationBase.PrivacyPolicyCommand.Execute(null); this.Cleanup(); })); e.Commands.Add(new SettingsCommand("tos", Strings.Resources.ViewTitleTermsOfService, (c) => { PlatformBase.CurrentCore.NavigationBase.TermsOfServiceCommand.Execute(null); this.Cleanup(); })); } catch (Exception ex) { PlatformBase.CurrentCore.Logger.LogError(ex, "Failed to display the web account manager UI."); throw ex; } finally { deferral.Complete(); } }
private async void OnAccountCommandsRequested( AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); // This scenario only supports a single account at one time. // If there already is an account, we do not include a provider in the list // This will prevent the add account button from showing up. await AddWebAccountProvidersToPane(e); await AddWebAccountsToPane(e); AddLinksAndDescription(e); deferral.Complete(); }
public async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); // This scenario only lets the user have one account at a time. // If there already is an account, we do not include a provider in the list // This will prevent the add account button from showing up. if (HasAccountStored()) { await AddWebAccountToPane(e); } else { await AddWebAccountProvidersToPane(e); } AddLinksAndDescription(e); deferral.Complete(); }
// This event handler is called when the Account settings pane is to be launched. private async void OnAccountCommandsRequested( AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { // In order to make async calls within this callback, the deferral object is needed AccountsSettingsPaneEventDeferral deferral = e.GetDeferral(); // 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 WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, consumerAuthority); WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked); e.WebAccountProviderCommands.Add(providerCommand); e.HeaderText = "Signing in with your Microsoft account allows syncing of your Sights2See data across all your devices"; // You can add links such as privacy policy, help, general account settings e.Commands.Add(new SettingsCommand("privacypolicy", "Privacy policy", PrivacyPolicyInvoked)); e.Commands.Add(new SettingsCommand("otherlink", "Other link", OtherLinkInvoked)); deferral.Complete(); }
/// <summary> /// Create login pane /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void BuildLoginPaneAsync(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args) { AccountsSettingsPaneEventDeferral deferral = args.GetDeferral(); bool isPresent = ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey); if (isPresent) { await AddAccount(args); } else { await AddAccountProvider(args); } args.HeaderText = "Describe what adding an account to your application will do for the user"; // You can add links such as privacy policy, help, general account settings //args.Commands.Add(new SettingsCommand("privacypolicy", "Privacy policy", PrivacyPolicyInvoked)); //args.Commands.Add(new SettingsCommand("otherlink", "Other link", OtherLinkInvoked)); deferral.Complete(); }
private async void Authenticator_AccountCommandsRequested( AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e) { AccountsSettingsPaneEventDeferral deferral = null; try { deferral = e.GetDeferral(); if (string.Equals("common", _authority.TenantId)) { _logger.Verbose("Displaying selector for common"); e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers"), WebAccountProviderCommandInvoked)); e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "organizations"), WebAccountProviderCommandInvoked)); } else if (string.Equals("organizations", _authority.TenantId)) { _logger.Verbose("Displaying selector for organizations"); e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "organizations"), WebAccountProviderCommandInvoked)); } else if (string.Equals("consumers", _authority.TenantId)) { _logger.Verbose("Displaying selector for consumers"); e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers"), WebAccountProviderCommandInvoked)); if (_isMsaPassthrough) { e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "organizations"), WebAccountProviderCommandInvoked)); } } else { _logger.Verbose("Displaying selector for tenanted authority"); e.WebAccountProviderCommands.Add( new WebAccountProviderCommand( await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", _authority.AuthorityInfo.CanonicalAuthority), WebAccountProviderCommandInvoked)); } //e.HeaderText = "Please select an account to log in with"; // TODO: this is English only, try removing it } finally { deferral?.Complete(); } }
public async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs) { AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral(); HttpResult <ManageInfo> result; using (AccountClient accountClient = ClientFactory.CreateAccountClient()) { result = await accountClient.GetManageInfoAsync(); } if (!result.Succeeded) { await ErrorDialog.ShowErrorsAsync(result.Errors); // The log off command is not available on the account settings page if there are no accounts, so log off now LogOff(); deferral.Complete(); return; } ManageInfo manageInfo = result.Content; this.username = manageInfo.UserName; this.localProvider = manageInfo.LocalLoginProvider; eventArgs.HeaderText = "Manage your account logins"; ////Add WebAccountProviders Dictionary <string, WebAccountProvider> webProviders = new Dictionary <string, WebAccountProvider>(); WebAccountProviderCommandInvokedHandler providerCommandHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler); foreach (ExternalLogin externalLogin in manageInfo.ExternalLoginProviders) { WebAccountProvider provider = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]); WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCommandHandler); eventArgs.WebAccountProviderCommands.Add(providerCommand); webProviders[provider.DisplayName] = provider; } WebAccountProvider localLoginProvider = new WebAccountProvider(manageInfo.LocalLoginProvider, manageInfo.LocalLoginProvider, null); webProviders[manageInfo.LocalLoginProvider] = localLoginProvider; ////Add WebAccounts and local accounts if available. bool hasLocalLogin = false; foreach (UserLoginInfo userLoginInfo in manageInfo.Logins) { WebAccountCommandInvokedHandler accountCommandHandler; SupportedWebAccountActions supportedActions = SupportedWebAccountActions.None; if (manageInfo.Logins.Length > 1) { supportedActions |= SupportedWebAccountActions.Remove; } if (userLoginInfo.LoginProvider == manageInfo.LocalLoginProvider) { hasLocalLogin = true; supportedActions |= SupportedWebAccountActions.Manage; accountCommandHandler = new WebAccountCommandInvokedHandler(LocalWebAccountInvokedHandler); } else { accountCommandHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler); } WebAccount webAccount = new WebAccount(webProviders[userLoginInfo.LoginProvider], userLoginInfo.ProviderKey, WebAccountState.Connected); WebAccountCommand webAccountCommand = new WebAccountCommand(webAccount, accountCommandHandler, supportedActions); eventArgs.WebAccountCommands.Add(webAccountCommand); } if (!hasLocalLogin) { WebAccountProviderCommandInvokedHandler localProviderCmdHandler = new WebAccountProviderCommandInvokedHandler(LocalProviderInvokedHandler); WebAccountProviderCommand localProviderCommand = new WebAccountProviderCommand(localLoginProvider, localProviderCmdHandler); eventArgs.WebAccountProviderCommands.Add(localProviderCommand); } SettingsCommand logOffCommand = new SettingsCommand("Logoff", "Log off", new UICommandInvokedHandler(LogOffHandler)); eventArgs.Commands.Add(logOffCommand); deferral.Complete(); }