protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // The AccountCommandsRequested event triggers before the Accounts settings pane is displayed
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
        }
Example #2
0
 public void GetAzureADToken(AuthSuccessCallback onAuthCompleted, AuthFailedCallback onAuthFailed)
 {
     this.OnAuthSuccess = onAuthCompleted;
     this.OnAuthFailed  = onAuthFailed;
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
     AccountsSettingsPane.Show();
 }
Example #3
0
        private async Task <WebAccountProvider> ShowPicker_UWPAsync()
        {
            await _synchronizationContext;

            AccountsSettingsPane retaccountPane = null;

            try
            {
                retaccountPane = AccountsSettingsPane.GetForCurrentView();
                retaccountPane.AccountCommandsRequested += Authenticator_AccountCommandsRequested;
                await AccountsSettingsPane.ShowAddAccountAsync();

                return(_provider);
            }
            catch (Exception e)
            {
                _logger.ErrorPii(e);
                throw;
            }
            finally
            {
                if (retaccountPane != null)
                {
                    retaccountPane.AccountCommandsRequested -= Authenticator_AccountCommandsRequested;
                }
            }
        }
Example #4
0
        public AccountService(INavigationService navigationService, IHttpClientFactory httpClientFactory)
        {
            _navigationService = navigationService;
            _httpClientFactory = httpClientFactory;

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;

            IdentityChecker.SampleIdentityConfigurationCorrect(NotRegisteredWarning, AzureActiveDirectoryClientId);
        }
Example #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // 弹出账号配置界面时触发的事件
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
        }
        private async void WebAccountProviderCommandInvoked(WebAccountProviderCommand command)
        {
            string token = string.Empty;

            // AccountClientID is ignored by MSA
            WebTokenRequest webTokenRequest = new WebTokenRequest(command.WebAccountProvider, AccountScopeRequested, AccountClientId);

            // If the user selected a specific account, RequestTokenAsync will return a token for that account.
            // The user may be prompted for credentials or to authorize using that account with your app
            // If the user selected a provider, the user will be prompted for credentials to login to a new account
            WebTokenRequestResult webTokenRequestResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);

            // If a token was successfully returned, then store the WebAccount Id into local app data
            // This Id can be used to retrieve the account whenever needed. To later get a token with that account
            // First retrieve the account with FindAccountAsync, and include that webaccount
            // as a parameter to RequestTokenAsync or RequestTokenSilentlyAsync
            if (webTokenRequestResult.ResponseStatus == WebTokenRequestStatus.Success)
            {
                WebTokenResponse webTokenResponse = webTokenRequestResult.ResponseData[0];
                userAccount = webTokenResponse.WebAccount;
                token       = webTokenResponse.Token;
            }

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

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= OnAccountCommandsRequested;

            OnAuthenticated?.Invoke(this, new AuthenticatedEventArgs(token));
        }
        private async Task <WebAccountProvider> ShowPickerAsync()
        {
            AccountsSettingsPane retaccountPane = null;

            try
            {
#if WINDOWS_APP
                retaccountPane = AccountsSettingsPane.GetForCurrentView();
                retaccountPane.AccountCommandsRequested += Authenticator_AccountCommandsRequested;
                await AccountsSettingsPane.ShowAddAccountAsync();
#else
                retaccountPane = AccountsSettingsPaneInterop.GetForWindow(_parentHandle);
                retaccountPane.AccountCommandsRequested += Authenticator_AccountCommandsRequested;
                await AccountsSettingsPaneInterop.ShowAddAccountForWindowAsync(_parentHandle);
#endif
                return(_provider);
            }
            catch (Exception e)
            {
                _logger.ErrorPii(e);
                throw;
            }
            finally
            {
                if (retaccountPane != null)
                {
                    retaccountPane.AccountCommandsRequested -= Authenticator_AccountCommandsRequested;
                }
            }
        }
 public LoginPage()
 {
     this.InitializeComponent();
     this.navigationHelper            = new NavigationHelper(this);
     this.navigationHelper.LoadState += navigationHelper_LoadState;
     this.navigationHelper.SaveState += navigationHelper_SaveState;
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += AccountCommandsRequested;
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            CreateLocalDataContainers();

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
        }
Example #11
0
 /// <summary>
 /// Preserves state associated with this page in case the application is suspended or the
 /// page is discarded from the navigation cache.  Values must conform to the serialization
 /// requirements of <see cref="SuspensionManager.SessionState"/>.
 /// </summary>
 /// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
 /// <param name="e">Event data that provides an empty dictionary to be populated with
 /// serializable state.</param>
 private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
 {
     if (accountSettings != null)
     {
         SettingsPane.GetForCurrentView().CommandsRequested -= accountSettings.CommandsRequested;
         AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= accountSettings.AccountCommandsRequested;
     }
 }
Example #12
0
        public void Auth()
        {
            CreateLocalDataContainers();
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;

            bool checkID = IdentityChecker.SampleIdentityConfigurationCorrect(AzureActiveDirectoryClientId);

            Windows.UI.ApplicationSettings.AccountsSettingsPane.Show();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // The AccountCommandsRequested event triggers before the Accounts settings pane is displayed
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;

            IdentityChecker.SampleIdentityConfigurationCorrect(NotRegisteredWarning);
        }
 public AuthenticationViewModel()
 {
     AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += BuildSettingsPaneAsync;
     if (!String.IsNullOrEmpty(Constants.FacebookAppId))
     {
         FacebookService.Instance.Initialize(Constants.FacebookAppId,
                                             FacebookPermissions.PublicProfile | FacebookPermissions.UserFriends);
     }
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is bool)
            {
                autoSignIn = (bool)e.Parameter;
            }

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
        }
        public Scenario5()
        {
            this.InitializeComponent();

            InitializeWebAccountProviders();
            InitializeWebAccounts();

            SettingsPane.GetForCurrentView().CommandsRequested += CommandsRequested;
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += AccountCommandsRequested;
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += _userAccountManager.BuildAccountPaneAsync;
            await _userAccountManager.SignInUserAccountSilentlyAsync();

            if (_userAccountManager.UserIsSignedIn)
            {
                Debug.WriteLine("Successful silent sign-in");
            }
        }
Example #18
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 #19
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 #20
0
 /// <summary>
 /// Displays the Web Account Manager for users to chose an account to authenticate with.
 /// </summary>
 /// <param name="successHandler">Call back for when an account is successfully choosen by the user.</param>
 /// <param name="failedHandler">Call back for when an error or cancelled UI occurs by the user.</param>
 public void Show(WebAccountManangerSuccessHandler successHandler, WebAccountManangerFailedHandler failedHandler)
 {
     if (this.ShowingUI == false)
     {
         AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
     }
     this.ShowingUI  = true;
     _successHandler = successHandler;
     _failedHandler  = failedHandler;
     AccountsSettingsPane.Show();
 }
Example #21
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 #22
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 #23
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();
            }
        }
        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);
            }
        }
        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 #26
0
        public MainPage()
        {
            this.InitializeComponent();

            //Handling titlebar
            var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;

            coreTitleBar.ExtendViewIntoTitleBar = true;
            UpdateTitleBarLayout(coreTitleBar);
            Window.Current.SetTitleBar(TitleBar);
            coreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;
            coreTitleBar.IsVisibleChanged     += CoreTitleBar_IsVisibleChanged;

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += BuildPaneAsync;

            //Finished initialization
            //Navigate to default page
            NavigationMenuList.SelectedIndex = 0;
        }
Example #27
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame != null && rootFrame.CanGoBack)
            {
                // Show UI in title bar if opted-in and in-app backstack is not empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Visible;
            }
            else
            {
                // Remove the UI from the title bar if in-app back stack is empty.
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    AppViewBackButtonVisibility.Collapsed;
            }

            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += BuildPaneAsync;
        }
        private async Task LogoffAndRemoveAccount()
        {
            if (ApplicationData.Current.LocalSettings.Values.ContainsKey(StoredAccountKey))
            {
                WebAccountProvider providertoDelete = await WebAuthenticationCoreManager.FindAccountProviderAsync(MicrosoftAccountProviderId, ConsumerAuthority);

                WebAccount accountToDelete = await WebAuthenticationCoreManager.FindAccountAsync(providertoDelete, (string)ApplicationData.Current.LocalSettings.Values[StoredAccountKey]);

                if (accountToDelete != null)
                {
                    await accountToDelete.SignOutAsync();
                }

                ApplicationData.Current.LocalSettings.Values.Remove(StoredAccountKey);
                ApplicationData.Current.LocalSettings.Values.Remove(StoredEmailKey);
                AccountListViewItem.Visibility = Visibility.Collapsed;
                SignInListViewItem.Visibility  = Visibility.Visible;

                await Shared.Helpers.LocalStore.PurgeLocalStoreAsync();

                App.HomesViewModel = new HomesViewModel();
                App.RoomsViewModel = new RoomsViewModel();

                Frame rootFrame = Window.Current.Content as Frame;

                if (rootFrame == null)
                {
                    rootFrame = new Frame();

                    Window.Current.Content = rootFrame;
                }

                if (rootFrame.Content == null)
                {
                    bool autoSignIn = false;
                    AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested -= OnAccountCommandsRequested;
                    rootFrame.Navigate(typeof(Views.SignIn.MainPage), autoSignIn);
                }

                Window.Current.Activate();
            }
        }
Example #29
0
        private void AccountControl_Click(object sender, RoutedEventArgs e)
        {
            ((Button)sender).IsEnabled = false;
            // TODO: move the callback registration to OnNavigatedTo
            try
            {
                if (!_isCallbackRegistered)
                {
                    AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;
                    _isCallbackRegistered = true;
                }

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

            ((Button)sender).IsEnabled = true;
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var device = AnalyticsInfo.VersionInfo.DeviceFamily;

            if (device == "Windows.Desktop" || device == "Windows.Tablet")
            {
                AppTitleBar.Visibility = Visibility.Visible;
                // Hide default title bar.
                var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
                coreTitleBar.ExtendViewIntoTitleBar = true;
                var applicationView = ApplicationView.GetForCurrentView();
                var titleBar        = applicationView.TitleBar;
                titleBar.ButtonBackgroundColor = Colors.Transparent;
            }
            AccountsSettingsPane.GetForCurrentView().AccountCommandsRequested += OnAccountCommandsRequested;

            user = await MicrosoftAccount.SignIn();

            AccountName.Text               = user.AccountName;
            AccountImage.Fill              = user.Image;
            SignInListViewItem.Visibility  = Visibility.Collapsed;
            AccountListViewItem.Visibility = Visibility.Visible;
        }