// 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();
        }
Example #2
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();
        }
        public Scenario5()
        {
            this.InitializeComponent();

            InitializeWebAccountProviders();
            InitializeWebAccounts();

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

            SignInWindows_button.IsEnabled = true;
        }
Example #5
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            CreateLocalDataContainers();

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;

            IdentityChecker.SampleIdentityConfigurationCorrect(NotRegisteredWarning, AzureActiveDirectoryClientId);
        }
Example #6
0
 /// <summary>
 /// Clean up after displaying the web account manager.
 /// </summary>
 private void Cleanup()
 {
     if (this.ShowingUI)
     {
         AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= OnAccountCommandsRequested;
     }
     this.ShowingUI  = false;
     _successHandler = null;
     _failedHandler  = null;
 }
Example #7
0
        private void Button_ShowAccountSettings(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;

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

            AccountsSettingsPane.Show();

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

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

            AccountsSettingsPane.Show();
        }
Example #12
0
        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();
        }
Example #13
0
 public async void Login()
 {
     if (await TryGetTokenSilentlyAsync())
     {
         LoginComplete?.Invoke(this, EventArgs.Empty);
         return;
     }
     else
     {
         AccountsSettingsPane.Show();
     }
 }
Example #14
0
 /// <summary>
 /// Logs the user in.
 /// </summary>
 public async void LoginClick()
 {
     if (ApplicationData.Current.RoamingSettings.Values.ContainsKey("IsLoggedIn") &&
         (bool)ApplicationData.Current.RoamingSettings.Values["IsLoggedIn"])
     {
         await LoginAsync();
     }
     else
     {
         AccountsSettingsPane.Show();
     }
 }
Example #15
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();
        }
Example #16
0
 public TodoPage()
 {
     this.InitializeComponent();
     this.navigationHelper            = new NavigationHelper(this);
     this.navigationHelper.LoadState += navigationHelper_LoadState;
     this.navigationHelper.SaveState += navigationHelper_SaveState;
     this.TodoPageModel   = new TodoPageModel();
     this.DataContext     = this.TodoPageModel;
     this.accountSettings = new AccountSettings();
     SettingsPane.GetForCurrentView().CommandsRequested += accountSettings.CommandsRequested;
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += accountSettings.AccountCommandsRequested;
 }
Example #17
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();
        }
Example #18
0
        private async Task <WebTokenRequestResult> SignInAsync(string resource)
        {
            var taskCompletionSource = new TaskCompletionSource <WebTokenRequestResult>();

            TypedEventHandler <AccountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs> AccountCommandsRequestedHandler = null;

            AccountCommandsRequestedHandler = async(s, e) =>
            {
                Debug.WriteLine("AccountCommandsRequestedHandler");

                AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= AccountCommandsRequestedHandler;

                // In order to make async calls within this callback, the deferral object is needed
                AccountsSettingsPaneEventDeferral deferral = e.GetDeferral();
                if (deferral != null)
                {
                    // The Microsoft account provider is always present in Windows 10 devices, even IoT Core, as is the Azure AD plugin.
                    var providerCommand = new WebAccountProviderCommand(await GetProvider(), async(command) =>
                    {
                        Debug.WriteLine("WebAccountProviderCommandInvokedHandler");

                        try
                        {
                            WebTokenRequest wtr = new WebTokenRequest(command.WebAccountProvider, _scope, _clientId);
                            if (resource != null)
                            {
                                wtr.Properties.Add("resource", resource);
                            }

                            var wtrr = await RequestTokenWithTimeout(wtr);
                            SaveToken(wtrr, resource);

                            taskCompletionSource.SetResult(wtrr);
                        }
                        catch (Exception ex)
                        {
                            ServiceUtil.LogService.Write("Web Token Request Error: " + ex.Message, LoggingLevel.Error);
                            taskCompletionSource.SetResult(null);
                        }
                    });

                    e.WebAccountProviderCommands.Add(providerCommand);

                    deferral.Complete();
                }
            };

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += AccountCommandsRequestedHandler;
            await AccountsSettingsPane.ShowAddAccountAsync();

            return(await taskCompletionSource.Task);
        }
Example #19
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();
        }
Example #20
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();
            }
        }
Example #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);
            }
        }
Example #22
0
        public static AccountsSettingsPane GetForWindow(IntPtr hWnd)
        {
            IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
                AccountsSettingsPane.As <IAccountsSettingsPaneInterop>();
            //Guid guid = typeof(AccountsSettingsPane).GUID;
            Guid guid = //WinRT.GuidGenerator.CreateIID(typeof(IAccountsSettingPane));
                        Guid.Parse("81EA942C-4F09-4406-A538-838D9B14B7E6");

            //IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
            //    (IAccountsSettingsPaneInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(AccountsSettingsPane));
            //Guid guid = typeof(AccountsSettingsPane).GetInterface("IAccountsSettingsPane").GUID;

            accountsSettingsPaneInterop.GetForWindow(hWnd, ref guid, out IntPtr result);
            return(MarshalInterface <AccountsSettingsPane> .FromAbi(result));
        }
Example #23
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();
        }
Example #24
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += MainPage_AccountCommandsRequested;
            await DocumentManager.LoadAccountAsync();

            if (DocumentManager.Account != null)
            {
                await DocumentManager.LoadItemsAsync();
            }
            else
            {
                AccountsSettingsPane.Show();
            }
        }
        private async void SignInButton_Click(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;

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

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

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

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

            if (silentToken != null)
            {
                OdManager.Token = silentToken;
                this.Frame.Navigate(typeof(AnnotatedAudio.View.SessionPicker), OdManager);
            }
            else
            {
                Debug.WriteLine("accountsettingspane show");
                AccountsSettingsPane.Show();
            }
        }
        public Scenario2()
        {
            this.InitializeComponent();

            try
            {
                // SettingsPane is the existing  Win8 API for the Settings Contract
                SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;
                //Adding AccountControl callback
                AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += MainPage_AccountCommandsRequested;
            }
            catch (Exception Error) // No stored credentials, so none to delete
            {
                DebugPrint(Error.Message);
            }
        }
 void CredentialDeletedHandler(CredentialCommand sender)
 {
     try
     {
         // callback invoked when the user requests deletion of the credential in the accounts flyout
         // System will invoke this callback after successfully deleting the credential from the vault
         // do post delete work
         // show accounts settings pane to reflect the new state
         AccountsSettingsPane.Show();
         DebugPrint("Your credential is removed from PasswordVault");
     }
     catch (Exception Error) // No stored credentials, so none to delete
     {
         DebugPrint(Error.Message);
     }
 }
        /// <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();
        }
        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();
        }
        private async void Initalise()
        {
            await Shared.Services.Storage.InitaliseAsync();

            LoadingHeader.Text = "Nearly finished..";
            await Shared.Services.Storage.SyncAsync();


            await App.HomesViewModel.Initalise();

            if (App.HomesViewModel.Homes.Count() == 0)
            {
                App.HomesViewModel.HomeName = "My Home";
                App.HomesViewModel.UserName = user.AccountName;
                App.HomesViewModel.AddHomeCommand.Execute(null);
            }
            try
            {
                App.RoomsViewModel.SelectedHomeId = App.HomesViewModel.SelectedHome.Id;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ActivationService.Initalise - Error loading rooms: " + ex.Message);
            }

            AppShell shell = Window.Current.Content as AppShell;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (shell == null)
            {
                // Create a AppShell to act as the navigation context and navigate to the first page
                shell = new AppShell();
            }

            // Place our app shell in the current Window
            Window.Current.Content = shell;

            if (shell.AppFrame.Content == null)
            {
                AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= OnAccountCommandsRequested;
                shell.AppFrame.Navigate(typeof(Views.Overview.MainPage));
            }

            Window.Current.Activate();
        }
Example #33
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();
        }
Example #34
0
        public static IAsyncAction ShowAddAccountForWindowAsync(IntPtr hWnd)
        {
            IWebAuthenticationCoreManagerInterop webAuthenticationCoreManagerInterop =
                WebAuthenticationCoreManager.As <IWebAuthenticationCoreManagerInterop>();

            IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
                AccountsSettingsPane.As <IAccountsSettingsPaneInterop>();
            //Guid guid = typeof(IAsyncAction).GUID;
            Guid guid = WinRT.GuidGenerator.CreateIID(typeof(IAsyncAction));

            //IAccountsSettingsPaneInterop accountsSettingsPaneInterop =
            //    (IAccountsSettingsPaneInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(AccountsSettingsPane));
            //Guid guid = typeof(IAsyncAction).GUID;

            accountsSettingsPaneInterop.ShowAddAccountForWindowAsync(hWnd, ref guid, out IntPtr result);

            return(MarshalInterface <IAsyncAction> .FromAbi(result));
        }
Example #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();
            }
        }
 public AccountsSettingsPaneEvents(AccountsSettingsPane This)
 {
     this.This = This;
 }
        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();
        }
        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();
        }
Example #39
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();
        }