Beispiel #1
0
        private async void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var deferral = args.GetDeferral();

            try
            {
                // MSA
                {
                    var provider = await GetProvider(MicrosoftProviderId, MsaAuthority);

                    var command = new AuthenticationCommand {
                        ClientId = MsaClientId, Scope = MsaClientId
                    };
                    WebAccountProviderCommand boundCommand = new WebAccountProviderCommand(provider, command.CommandInvoked);
                    args.WebAccountProviderCommands.Add(boundCommand);
                }

                // AAD
                // https://blogs.technet.microsoft.com/enterprisemobility/2015/08/03/develop-windows-universal-apps-with-azure-ad-and-the-windows-10-identity-api/
                {
                    var provider = await GetProvider(MicrosoftProviderId, MicrosoftProviderId + "/" /*AadAuthority*/);

                    var command = new AuthenticationCommand {
                        ClientId = AadClientId, Scope = string.Empty
                    };
                    var boundCommand = new WebAccountProviderCommand(provider, command.CommandInvoked);
                    args.WebAccountProviderCommands.Add(boundCommand);
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
Beispiel #2
0
        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();
        }
        /// <summary>
        /// Creates an AccountsSettingsPane with options for MSA or Facebook login.
        /// </summary>
        private static async void BuildSettingsPaneAsync(AccountsSettingsPane s,
                                                         AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral = e.GetDeferral();

            e.HeaderText = _paneMessage + "Get signed in to Lunch Scheduler.  " +
                           "You can use an existing Microsoft or Facebook account.";

            // Microsoft account
            var msa = new WebAccountProviderCommand(
                await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers"),
                MicrosoftAccountAuth);

            e.WebAccountProviderCommands.Add(msa);

            // Facebook
            // Built-in provider exists only on phone; if not availble, use WAB as a fallback
            var fbProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://facebook.com");

            var fb = new WebAccountProviderCommand(
                fbProvider ??
                new WebAccountProvider("LunchScheduler", "Facebook", new Uri(@"ms-appx:///Assets/FbIcon.png")),
                FacebookAuth);

            e.WebAccountProviderCommands.Add(fb);

            // Help commands
            e.Commands.Add(new SettingsCommand("help", "Get help signing in",
                                               async x => await Launcher.LaunchUriAsync(new Uri("http://bing.com"))));
            e.Commands.Add(new SettingsCommand("privacy", "Privacy policy",
                                               async x => await Launcher.LaunchUriAsync(new Uri("http://bing.com"))));

            deferral.Complete();
        }
        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();
            WebAccountProviderCommand         providerCommand = new WebAccountProviderCommand(await MicrosoftAccount.GetProvider(), WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);
            deferral.Complete();
        }
Beispiel #7
0
        private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            AccountsSettingsPaneEventDeferral deferral = args.GetDeferral();

            await AddWebAccountProvider(args);

            AddLinksAndDescription(args);
            deferral.Complete();
        }
        /// <summary>
        /// This event is generated when the user clicks on Accounts command in settings pane. During this event, add your
        /// WebAccountProviderCommand, WebAccountCommand, CredentialCommand and  SettingsCommand objects to make them available to the
        /// AccountsSettingsPane UI.
        /// </summary>
        /// <param name="accountsSettingsPane">Instance that triggered the event.</param>
        /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
        private void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            var deferral = eventArgs.GetDeferral();

            //Add header text.
            eventArgs.HeaderText = "This is sample text. You can put a message here to give context to user. This section is optional.";

            //Add WebAccountProviders
            WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
            WebAccountProviderCommand facebookProviderCommand          = new WebAccountProviderCommand(facebookProvider, WebAccountProviderInvokedHandler);

            eventArgs.WebAccountProviderCommands.Add(facebookProviderCommand);
            WebAccountProviderCommand twitterProviderCommand = new WebAccountProviderCommand(twitterProvider, WebAccountProviderInvokedHandler);

            eventArgs.WebAccountProviderCommands.Add(twitterProviderCommand);

            //Add WebAccounts if available.
            WebAccountCommandInvokedHandler accountCmdHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);

            if (isFacebookUserLoggedIn)
            {
                facebookAccount = new WebAccount(facebookProvider, facebookUserName, WebAccountState.Connected);
                WebAccountCommand facebookAccountCommand = new WebAccountCommand(
                    facebookAccount, WebAccountInvokedHandler,
                    SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(facebookAccountCommand);
            }

            if (isTwitterUserLoggedIn)
            {
                twitterAccount = new WebAccount(twitterProvider, twitterUserName, WebAccountState.Connected);
                WebAccountCommand twitterAccountCommand = new WebAccountCommand(
                    twitterAccount, WebAccountInvokedHandler,
                    SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(twitterAccountCommand);
            }

            // Add links if needed.
            Object commandID = 1;
            UICommandInvokedHandler globalLinkInvokedHandler = new UICommandInvokedHandler(GlobalLinkInvokedhandler);
            SettingsCommand         command = new SettingsCommand(
                commandID,
                "More details",
                globalLinkInvokedHandler);

            eventArgs.Commands.Add(command);

            SettingsCommand command1 = new SettingsCommand(
                commandID,
                "Privacy policy",
                globalLinkInvokedHandler);

            eventArgs.Commands.Add(command1);

            deferral.Complete();
        }
Beispiel #9
0
        /// <summary>
        /// Initializes the AccountsSettingsPane with AAD login.
        /// </summary>
        private async void BuildAccountsPane(AccountsSettingsPane sender,
                                             AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var deferral = args.GetDeferral();
            var command  = new WebAccountProviderCommand(await GetAadProviderAsync(), async(x) =>
                                                         await LoginAsync());

            args.WebAccountProviderCommands.Add(command);
            deferral.Complete();
        }
Beispiel #10
0
#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();
            }
        }
Beispiel #11
0
        private async void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var d           = args.GetDeferral();
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com",
                "consumers");

            var command = new WebAccountProviderCommand(msaProvider, GetMsaTokenAsync);

            args.WebAccountProviderCommands.Add(command);
            d.Complete();
        }
Beispiel #12
0
        private async void BuildPaneAsync(AccountsSettingsPane s,
                                          AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral    = e.GetDeferral();
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                "https://login.microsoft.com", "consumers");

            var command = new WebAccountProviderCommand(msaProvider, GetMsaTokenAsync);

            e.WebAccountProviderCommands.Add(command);
            deferral.Complete();
        }
Beispiel #13
0
        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();
        }
Beispiel #14
0
        private async void BuildAccountsSettingsPaneAsync(AccountsSettingsPane s, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            s.AccountCommandsRequested -= BuildAccountsSettingsPaneAsync;

            var deferral = e.GetDeferral();

            e.HeaderText = resourceService.GetString("SignInDescription");
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");
            var command = new WebAccountProviderCommand(msaProvider, GetMsaToken);
            e.WebAccountProviderCommands.Add(command);

            deferral.Complete();
        }
Beispiel #15
0
        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();
            }
        }
Beispiel #16
0
        private async void BuildAccountsSettingsPaneAsync(AccountsSettingsPane s, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            s.AccountCommandsRequested -= BuildAccountsSettingsPaneAsync;

            var deferral = e.GetDeferral();

            e.HeaderText = resourceService.GetString("SignInDescription");
            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");

            var command = new WebAccountProviderCommand(msaProvider, GetMsaToken);

            e.WebAccountProviderCommands.Add(command);

            deferral.Complete();
        }
        /// <summary>
        /// This method customizes the accounts settings pane to setup user authentication with Microsoft accounts.
        /// You need to register this method to the AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested event.
        /// Don't forget to also remove the event handler (for example when user navigates away from your page).
        /// </summary>
        public async void BuildAccountPaneAsync(
            AccountsSettingsPane s,
            AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral = e.GetDeferral();

            var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                MicrosoftAccountProviderId,
                ConsumerAuthority);

            var command = new WebAccountProviderCommand(msaProvider, SignInUserAccountAsync);

            e.WebAccountProviderCommands.Add(command);

            deferral.Complete();
        }
Beispiel #18
0
        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 void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            var deferral = eventArgs.GetDeferral();

            ResourceLoader _res = ResourceLoader.GetForCurrentView();

            eventArgs.HeaderText = _res.GetString("LoginDescription");
            eventArgs.WebAccountProviderCommands.Clear();
            eventArgs.WebAccountCommands.Clear();

#if STEP2
            WebAccountProviderCommand googlePlusProviderCommand = new WebAccountProviderCommand(_app.SynchroManager.GetProvider(SynchroManager.ServerName.GooglePlus), WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(googlePlusProviderCommand);

            WebAccountProviderCommand facebookProviderCommand = new WebAccountProviderCommand(_app.SynchroManager.GetProvider(SynchroManager.ServerName.Facebook), WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(facebookProviderCommand);
#endif
            WebAccountProviderCommand dropboxProviderCommand = new WebAccountProviderCommand(_app.SynchroManager.GetProvider(SynchroManager.ServerName.Dropbox), WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(dropboxProviderCommand);

            WebAccountProviderCommand usbProviderCommand = new WebAccountProviderCommand(_app.SynchroManager.GetProvider(SynchroManager.ServerName.Usb), WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(usbProviderCommand);

#if STEP2
            if (_app.SynchroManager.LoggedIn(SynchroManager.ServerName.Facebook))
            {
                eventArgs.WebAccountCommands.Add(_app.SynchroManager.GetAccount(SynchroManager.ServerName.Facebook));
            }

            if (_app.SynchroManager.LoggedIn(SynchroManager.ServerName.GooglePlus))
            {
                eventArgs.WebAccountCommands.Add(_app.SynchroManager.GetAccount(SynchroManager.ServerName.GooglePlus));
            }
#endif
            if (_app.SynchroManager.LoggedIn(SynchroManager.ServerName.Dropbox))
            {
                eventArgs.WebAccountCommands.Add(_app.SynchroManager.GetAccount(SynchroManager.ServerName.Dropbox));
            }

            if (_app.SynchroManager.LoggedIn(SynchroManager.ServerName.Usb))
            {
                eventArgs.WebAccountCommands.Add(_app.SynchroManager.GetAccount(SynchroManager.ServerName.Usb));
            }

            deferral.Complete();
        }
Beispiel #20
0
        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();
        }
Beispiel #21
0
        private void BuildPaneAsync(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var deferral = e.GetDeferral();

            e.HeaderText = "Sign in to get access to live tiles and notifications";

            var googleProvider  = new WebAccountProvider("youtube", "Youtube", new Uri("ms-appx:///Assets/Images/logo.png"));
            var providerCommand = new WebAccountProviderCommand(googleProvider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);

            List <WebAccount> accounts = App.GetAllAccounts();

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }

            deferral.Complete();
        }
Beispiel #22
0
        private async void OnAccountCommandsRequested(
            AccountsSettingsPane sender,
            AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var 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);
            }

            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();
        }
Beispiel #24
0
        /// <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 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 = Strings.Account.TextWebAccountManagerSignUpDescription;

                // You can add links such as privacy policy, help, general account settings
                e.Commands.Add(new SettingsCommand("privacypolicy", Strings.Resources.ViewTitlePrivacyPolicy, (c) => { Platform.Current.Navigation.NavigateToPrivacyPolicyCommand.Execute(null); this.Cleanup(); }));
                e.Commands.Add(new SettingsCommand("tos", Strings.Resources.ViewTitleTermsOfService, (c) => { Platform.Current.Navigation.NavigateToTermsOfServiceCommand.Execute(null); this.Cleanup(); }));
            }
            catch(Exception ex)
            {
                Platform.Current.Logger.LogError(ex, "Failed to display the web account manager UI.");
                throw ex;
            }
            finally
            {
                deferral.Complete();
            }
        }
        private static async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // In order to make async calls within this callback, the deferral object is needed
            var 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   
            var webAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(
                AccountProviderId, Authority);

            var providerCommand = new WebAccountProviderCommand(webAccountProvider,
                async (c) =>
                {
                    try
                    {
                        currentToken = await GetTokenHelperAsync(c.WebAccountProvider, GraphResourceId);

                        DiscoveryClient discoveryClient = new DiscoveryClient(
                                async () => await GetTokenHelperAsync(null, DiscoveryResourceId));

                        //Get capabilities
                        capabilities = await discoveryClient.DiscoverCapabilitiesAsync() as Dictionary<string, CapabilityDiscoveryResult>;


                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        SignOutAsync().Wait();
                        tcs.TrySetResult(false);
                    }
                    var isValid = !String.IsNullOrEmpty(currentToken);

                    if (!isValid)
                        await SignOutAsync();

                    tcs.TrySetResult(isValid);
                });

            e.WebAccountProviderCommands.Add(providerCommand);

            deferral.Complete();
        }
        void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            // Callback invoked to request the app for accounts when the accounts flyout is about to be displayed
            // Get the Deferral object and do some async operation if needed
            var Deferral = args.GetDeferral();

            // do some async operation
            //Uri uri = new Uri("ms-appx:///Assets/Smalllogo.png");
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);


            // Add CredLocker Credentials
            CredentialCommandCredentialDeletedHandler credDeletedHandler = new CredentialCommandCredentialDeletedHandler(CredentialDeletedHandler);

            Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
            IReadOnlyList <PasswordCredential>         creds = vault.RetrieveAll();

            if (creds.Count == 0)
            {
                args.HeaderText = "There is not credential saved by the sample app, please go to Scenario 1 and add some credential, then try again.";
            }
            else
            {
                args.HeaderText = "Here are the credentials saved by sample app in Scenario 1.";
            }

            foreach (PasswordCredential c in creds)
            {
                try
                {
                    CredentialCommand credCommand1 = new CredentialCommand(c, credDeletedHandler);
                    // Deleted is invoked after the system deletes the credential
                    args.CredentialCommands.Add(credCommand1);
                }
                catch (Exception Error) // Stored credential was deleted
                {
                    DebugPrint(Error.ToString());
                }
            }

            try
            {
                // Add Global commands
                Object commandID = 1;
                UICommandInvokedHandler appCmdInvokedHandler = new UICommandInvokedHandler(CommandInvokedHandler);

                // SettingsCommand is an existing WinRT class used in the SettingsPane
                SettingsCommand command = new SettingsCommand(
                    commandID,
                    "App Specific Command Label...",
                    appCmdInvokedHandler);
                args.Commands.Add(command);
                // Add more commands here
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.Message);
            }

            // Complete the Deferral()
            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();
        }
        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();
        }
Beispiel #30
0
        /// <summary>
        /// This event is generated when the user clicks on Accounts command in settings pane. During this event, add your
        /// WebAccountProviderCommand, WebAccountCommand, CredentialCommand and  SettingsCommand objects to make them available to the
        /// AccountsSettingsPane UI.
        /// </summary>
        /// <param name="accountsSettingsPane">Instance that triggered the event.</param>
        /// <param name="eventArgs">Event data describing the conditions that led to the event.</param>
        private void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            var deferral = eventArgs.GetDeferral();

            //Add header text.
            eventArgs.HeaderText = "This is sample text. You can put a message here to give context to user. This section is optional.";

            //Add WebAccountProviders
            WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
            WebAccountProviderCommand facebookProviderCommand = new WebAccountProviderCommand(facebookProvider, WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(facebookProviderCommand);
            WebAccountProviderCommand twitterProviderCommand = new WebAccountProviderCommand(twitterProvider, WebAccountProviderInvokedHandler);
            eventArgs.WebAccountProviderCommands.Add(twitterProviderCommand);

            //Add WebAccounts if available.
            WebAccountCommandInvokedHandler accountCmdHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);

            if (isFacebookUserLoggedIn)
            {
                facebookAccount = new WebAccount(facebookProvider, facebookUserName, WebAccountState.Connected);
                WebAccountCommand facebookAccountCommand = new WebAccountCommand(
                facebookAccount, WebAccountInvokedHandler,
                SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(facebookAccountCommand);
            }

            if (isTwitterUserLoggedIn)
            {
                twitterAccount = new WebAccount(twitterProvider, twitterUserName, WebAccountState.Connected);
                WebAccountCommand twitterAccountCommand = new WebAccountCommand(
                twitterAccount, WebAccountInvokedHandler,
                SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                eventArgs.WebAccountCommands.Add(twitterAccountCommand);
            }

            // Add links if needed.
            Object commandID = 1;
            UICommandInvokedHandler globalLinkInvokedHandler = new UICommandInvokedHandler(GlobalLinkInvokedhandler);
            SettingsCommand command = new SettingsCommand(
                commandID,
                "More details",
                globalLinkInvokedHandler);
            eventArgs.Commands.Add(command);

            SettingsCommand command1 = new SettingsCommand(
                commandID,
                "Privacy policy",
                globalLinkInvokedHandler);
            eventArgs.Commands.Add(command1);

            deferral.Complete();

        }
        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();
        }
Beispiel #32
0
        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();
        }
Beispiel #33
0
        void MainPage_AccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
         
            // Callback invoked to request the app for accounts when the accounts flyout is about to be displayed
            // Get the Deferral object and do some async operation if needed           
            var Deferral = args.GetDeferral();

            // do some async operation 
            //Uri uri = new Uri("ms-appx:///Assets/Smalllogo.png");
            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

  
            // Add CredLocker Credentials     
            CredentialCommandCredentialDeletedHandler credDeletedHandler = new CredentialCommandCredentialDeletedHandler(CredentialDeletedHandler);

            Windows.Security.Credentials.PasswordVault vault = new Windows.Security.Credentials.PasswordVault();
            IReadOnlyList<PasswordCredential> creds = vault.RetrieveAll();

            if (creds.Count == 0)
                args.HeaderText = "There is not credential saved by the sample app, please go to Scenario 1 and add some credential, then try again.";
            else
                args.HeaderText = "Here are the credentials saved by sample app in Scenario 1.";

            foreach (PasswordCredential c in creds)
            {
                try
                {
                    CredentialCommand credCommand1 = new CredentialCommand(c, credDeletedHandler);
                    // Deleted is invoked after the system deletes the credential
                    args.CredentialCommands.Add(credCommand1);
                }
                catch (Exception Error) // Stored credential was deleted
                {
                    DebugPrint(Error.ToString());
                }
            }

            try
            {
                // Add Global commands     
                Object commandID = 1;
                UICommandInvokedHandler appCmdInvokedHandler = new UICommandInvokedHandler(CommandInvokedHandler);

                // SettingsCommand is an existing WinRT class used in the SettingsPane
                SettingsCommand command = new SettingsCommand(
                                                    commandID,
                                                    "App Specific Command Label...",
                                                    appCmdInvokedHandler);
                args.Commands.Add(command);
                // Add more commands here
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.Message);
            }

            // Complete the Deferral()
            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();
            }
        }
        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();
        }