/// <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();
        }
Esempio n. 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();
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            WebAccountProvider web      = new WebAccountProvider("818", "MicrosoftAccount", new Uri("ms-appdata:///local/ProfilePicture.jpg"));
            WebAccount         account2 = new WebAccount(web, (string)ApplicationData.Current.LocalSettings.Values[StoredEmailKey], WebAccountState.Connected);

            if (account == null)
            {
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredEmailKey))
            {
                WebAccountCommand command = new WebAccountCommand(account2, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
        // 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();
        }
        // 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();
        }
Esempio n. 6
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 void AddLinksAndDescription(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            e.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
            e.Commands.Add(new SettingsCommand("privacypolicy", "Privacy Policy", PrivacyPolicyInvoked));
            e.Commands.Add(new SettingsCommand("otherlink", "Other Link", OtherLinkInvoked));
        }
        private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccount account = await GetWebAccount();

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);

            e.WebAccountCommands.Add(command);
        }
        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 Task AddWebAccountProvider(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);
        }
Esempio n. 11
0
        private void AddLinksAndDescription(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            e.HeaderText = "Signing in lets you sync your decks across 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));
        }
Esempio n. 12
0
        private async void OnAccountCommandsRequested(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            AccountsSettingsPaneEventDeferral deferral = args.GetDeferral();

            await AddWebAccountProvider(args);

            AddLinksAndDescription(args);
            deferral.Complete();
        }
Esempio n. 13
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();
        }
Esempio n. 14
0
        private async Task AddWebAccountsToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List <WebAccount> accounts = await GetAllAccounts();

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
                e.WebAccountCommands.Add(command);
            }
        }
Esempio n. 15
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();
            }
        }
Esempio n. 16
0
        private async Task AddWebAccountProvidersToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // The order of providers displayed is determined by the order provided to the Accounts pane
            List <WebAccountProvider> providers = await GetAllProviders();

            foreach (WebAccountProvider provider in providers)
            {
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);
                e.WebAccountProviderCommands.Add(providerCommand);
            }
        }
Esempio n. 17
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();
        }
Esempio n. 18
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();
        }
Esempio n. 19
0
        private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            var taskAccounts = WebAccountManager.FindAllProviderWebAccountsAsync().AsTask <IReadOnlyList <WebAccount> >();

            taskAccounts.Wait();
            var accounts = taskAccounts.Result;

            foreach (WebAccount account in accounts)
            {
                WebAccountCommand command = new WebAccountCommand(account, WebAccountCommandInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
        }
Esempio n. 20
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();
        }
Esempio n. 21
0
        private void MainPage_AccountCommandsRequested(AccountsSettingsPane sender,
			AccountsSettingsPaneCommandsRequestedEventArgs args)
        {
            var credDeletedHandler = new CredentialCommandCredentialDeletedHandler(h => AccountsSettingsPane.Show());

            var vault = new PasswordVault();
            var creds = vault.RetrieveAll();

            foreach (PasswordCredential c in creds)
            {
                var credCommand1 = new CredentialCommand(c, credDeletedHandler);
                args.CredentialCommands.Add(credCommand1);
            }
        }
Esempio n. 22
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();
            }
        }
        private async Task AddWebAccountProvider(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // 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
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);

            e.WebAccountProviderCommands.Add(providerCommand);
        }
Esempio n. 24
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();
        }
        private async Task AddWebAccountProvidersToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List <WebAccountProvider> providers = new List <WebAccountProvider>();

            // Microsoft account and Azure AD providers will always return. Non-installed plugins or incorrect identities will return null
            providers.Add(await GetProvider(MicrosoftProviderId, MicrosoftAccountAuthority));
            providers.Add(await GetProvider(MicrosoftProviderId, AzureActiveDirectoryAuthority));
            providers.Add(await GetProvider(AppSpecificProviderId));

            foreach (WebAccountProvider provider in providers)
            {
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);
                e.WebAccountProviderCommands.Add(providerCommand);
            }
        }
        /// <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();
        }
Esempio n. 27
0
        // 将指定的 web 账号添加到账号管理界面中
        private async Task ShowLogoutUI(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

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

            if (account != null)
            {
                // 最后一个参数用于指定当用户选择了账号后,会出现哪些功能按钮(我这里测试只有 SupportedWebAccountActions.Remove 是有效的)
                WebAccountCommand command = new WebAccountCommand(account, WebAccountCommandInvoked, SupportedWebAccountActions.Remove);
                e.WebAccountCommands.Add(command);
            }
            else
            {
                _userId = null;
            }
        }
Esempio n. 28
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();
        }
Esempio n. 29
0
        private async Task AddSelectorsAsync(AccountsSettingsPaneCommandsRequestedEventArgs args, bool addOrgAccounts, bool addMsaAccounts, string tenantId = null)
        {
            if (addOrgAccounts)
            {
                args.WebAccountProviderCommands.Add(
                    new WebAccountProviderCommand(
                        await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", tenantId ?? "organizations"),
                        WebAccountProviderCommandInvoked));
            }

            if (addMsaAccounts)
            {
                args.WebAccountProviderCommands.Add(
                    new WebAccountProviderCommand(
                        await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers"),
                        WebAccountProviderCommandInvoked));
            }
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String     accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account   = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                // The account has most likely been deleted in Windows settings
                // Unless there would be significant data loss, you should just delete the account
                // If there would be significant data loss, prompt the user to either re-add the account, or to remove it
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);

            e.WebAccountCommands.Add(command);
        }
Esempio n. 31
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();
        }
Esempio n. 32
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();
        }
Esempio n. 33
0
        private async Task AddWebAccountProvidersToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            try
            {
                foreach (var provider in Provider.All)
                {
                    WebAccountProvider webAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(provider.Id);

                    Debug.Assert(webAccountProvider != null);
                    if (webAccountProvider != null)
                    {
                        WebAccountProviderCommand command = new WebAccountProviderCommand(webAccountProvider, WebAccountProviderCommandInvoked);
                        e.WebAccountProviderCommands.Add(command);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugPrint("AddWebAccountProvidersToPane exception: " + ex.Message);
            }
        }
Esempio n. 34
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();
        }
Esempio n. 35
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 = 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();
        }
        private void AddLinksAndDescription(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            e.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
            e.Commands.Add(new SettingsCommand("privacypolicy", "Privacy Policy", PrivacyPolicyInvoked));
            e.Commands.Add(new SettingsCommand("otherlink", "Other Link", OtherLinkInvoked));
        }
        private async Task AddWebAccount(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            String accountID = (String)ApplicationData.Current.LocalSettings.Values[StoredAccountKey];
            WebAccount account = await WebAuthenticationCoreManager.FindAccountAsync(provider, accountID);

            if (account == null)
            {
                // The account has most likely been deleted in Windows settings
                // Unless there would be significant data loss, you should just delete the account
                // If there would be significant data loss, prompt the user to either re-add the account, or to remove it
                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
            }

            WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove);
            e.WebAccountCommands.Add(command);
        }
        private async Task AddWebAccountProvider(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // 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   
            WebAccountProvider provider = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

            WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);
            e.WebAccountProviderCommands.Add(providerCommand);
        }
        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();
        }
Esempio n. 41
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();
        }
        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();
        }
      private async Task AddWebAccountToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
      {
          WebAccount account = await GetWebAccount();
 
          WebAccountCommand command = new WebAccountCommand(account, WebAccountInvoked, SupportedWebAccountActions.Remove | SupportedWebAccountActions.Manage);
          e.WebAccountCommands.Add(command);
      }
        private async Task AddWebAccountProvidersToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            // The order of providers displayed is determined by the order provided to the Accounts pane
            List<WebAccountProvider> providers = await GetAllProviders();

            foreach (WebAccountProvider provider in providers)
            {
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);
                e.WebAccountProviderCommands.Add(providerCommand);
            }
        }
        private async Task AddWebAccountProvidersToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List<WebAccountProvider> providers = new List<WebAccountProvider>();

            // Microsoft account and Azure AD providers will always return. Non-installed plugins or incorrect identities will return null
            providers.Add(await GetProvider(MicrosoftProviderId, MicrosoftAccountAuthority));
            providers.Add(await GetProvider(MicrosoftProviderId, AzureActiveDirectoryAuthority));
            providers.Add(await GetProvider(AppSpecificProviderId));

            foreach (WebAccountProvider provider in providers)
            {
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, WebAccountProviderCommandInvoked);
                e.WebAccountProviderCommands.Add(providerCommand);
            }
        }
        private async Task AddWebAccountsToPane(AccountsSettingsPaneCommandsRequestedEventArgs e)
        {
            List<WebAccount> accounts = await GetAllAccounts();

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