/// <summary> /// This method is used to prompt to login screen. /// </summary> /// <returns>True if sign in successfully, otherwise false</returns> public async Task <bool> SignInAsync() { var success = false; try { success = await GraphService.TryLoginAsync(); } catch (Exception ex) { SignInFailed?.Invoke(this, new SignInFailedEventArgs(ex)); } if (success) { AutomationProperties.SetName(this, string.Empty); Flyout = GenerateMenuItems(); SignInCompleted?.Invoke(this, new SignInEventArgs() { GraphClient = GraphService.GraphProvider }); return(true); } return(false); }
public DevicePortalLoginControl() { InitializeComponent(); Loaded += DevicePortalLoginControl_Loaded; Unloaded += DevicePortalLoginControl_Unloaded; ViewModel.SignInCompleted += (s, e) => SignInCompleted?.Invoke(s, e); ViewModel.IsCancelVisible = ShowCancelButton; }
private MenuFlyout GenerateMenuItems() { MenuFlyout menuFlyout = new MenuFlyout(); if (AllowSignInAsDifferentUser) { MenuFlyoutItem signinanotherItem = new MenuFlyoutItem { Text = SignInAnotherUserDefaultText }; AutomationProperties.SetName(signinanotherItem, SignInAnotherUserDefaultText); signinanotherItem.Click += async(object sender, RoutedEventArgs e) => { try { if (await GraphService.ConnectForAnotherUserAsync()) { var graphClient = GraphService.GraphProvider; SignInCompleted?.Invoke(this, new SignInEventArgs() { GraphClient = graphClient }); CurrentUserId = (await GraphService.User.GetProfileAsync(new MicrosoftGraphUserFields[1] { MicrosoftGraphUserFields.Id })).Id; } } catch (MsalServiceException ex) { // Swallow error in case of authentication cancellation. if (ex.ErrorCode != "authentication_canceled" && ex.ErrorCode != "access_denied") { throw ex; } } }; menuFlyout.Items.Add(signinanotherItem); } MenuFlyoutItem signoutItem = new MenuFlyoutItem { Text = SignOutDefaultText }; AutomationProperties.SetName(signoutItem, SignOutDefaultText); signoutItem.Click += async(object sender, RoutedEventArgs e) => await SignOutAsync(); menuFlyout.Items.Add(signoutItem); return(menuFlyout); }
public void TearDownVM() { if (!_finalSignInEventFired) { _finalSignInEventFired = true; SignInCompleted?.Invoke(this, new SignInCompletedArgs { IsSuccessful = false, IsUserInitiated = true, }); } }
/// <summary> /// This method is used to prompt to login screen. /// </summary> /// <returns>True if sign in successfully, otherwise false</returns> public async Task <bool> SignInAsync() { if (await GraphService.TryLoginAsync()) { AutomationProperties.SetName(this, string.Empty); Flyout = GenerateMenuItems(); SignInCompleted?.Invoke(this, new SignInEventArgs() { GraphClient = GraphService.GraphProvider }); return(true); } return(false); }
public async Task <bool> SignInAsync(bool isUserInitiated = false) { await _semaphoreSlim.WaitAsync(); try { // Don't try signing in again if we're already signed in if (_isSignedIn) { return(true); } IsInputEnabled = false; _isSignedIn = await DevicePortalUtil.IsSignedInAsync(); if (!_isSignedIn) { _isSignedIn = await DevicePortalUtil.SignInAsync(Username, Password); } _finalSignInEventFired = _isSignedIn; SignInCompleted?.Invoke(this, new SignInCompletedArgs { IsSuccessful = _isSignedIn, IsUserInitiated = isUserInitiated, }); IsTransitionVisible = false; IsVisible = IsSignInVisible = IsInputEnabled = !_isSignedIn; return(_isSignedIn); } finally { _semaphoreSlim.Release(); } }