Ejemplo n.º 1
0
        protected async void CheckForExistingLoginAsync(AuthValidationMode authValidationMode, AuthenticationMode authMode)
        {
            string serializedAuthStatus = AuthManager.Instance.RetrieveProtectedString(Constants.AuthStatusKey);

            if (!String.IsNullOrEmpty(serializedAuthStatus))
            {
                var aS = AuthStatus.DeserializeFromString(serializedAuthStatus);
                //consider that a change in Authmode is possible between versions of an app, so check if the saved token may be trusted
                if (AuthenticationMode.Authorize.Equals(authMode) && !aS.IsAuthorized || AuthenticationMode.Identify.Equals(authMode) && aS.IsAuthorized)
                {
                    return;
                }

                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    this.VM.IsShowOverlay = true;
                    try
                    {
                        SystemTray.ProgressIndicator.IsVisible = true;
                        if (await aS.CheckIfStillValidAsync())
                        {
                            AuthManager.Instance.CurrentAuthStatus = aS;
                            NavigationService.Navigate(AuthManager.Instance.SuccessRedirect);
                        }
                        else
                        {
                            Dispatcher.BeginInvoke(() => { MessageBox.Show(LocalizedStrings.LocalizedResources.AuthNoMemberError); });
                        }
                    }
                    catch (WebTransferException)
                    {
                        if (AuthValidationMode.Graceful.Equals(authValidationMode))
                        {
                            NavigationService.Navigate(AuthManager.Instance.SuccessRedirect);
                        }
                        else
                        {
                            Dispatcher.BeginInvoke(() => { MessageBox.Show(LocalizedStrings.LocalizedResources.AuthNetworkError); });
                        }
                    }
                    finally
                    {
                        SystemTray.ProgressIndicator.IsVisible = false;
                        this.VM.IsShowOverlay = false;
                    }
                }
                else
                {
                    if (AuthValidationMode.Graceful.Equals(authValidationMode))
                    {
                        NavigationService.Navigate(AuthManager.Instance.SuccessRedirect);
                    }
                    Dispatcher.BeginInvoke(() => { MessageBox.Show(LocalizedStrings.LocalizedResources.AuthNetworkError); });
                }
            }
        }
Ejemplo n.º 2
0
        //;

        internal async Task <bool> CheckAndHandleExistingTokenAsync(AuthenticationMode authMode, AuthValidationMode validationMode)
        {
            string serializedAuthStatus = await RetrieveProtectedStringAsync(ConstantsUniversal.AuthStatusKey);

            if (!String.IsNullOrEmpty(serializedAuthStatus))
            {
                var aS = AuthStatus.DeserializeFromString(serializedAuthStatus);
                //consider that a change in Authmode is possible between versions of an app, so check if the saved token may be trusted
                if (AuthenticationMode.Authorize.Equals(authMode) && !aS.IsAuthorized || AuthenticationMode.Identify.Equals(authMode) && aS.IsAuthorized)
                {
                    return(false);
                }
                else if (NetworkInterface.GetIsNetworkAvailable())
                {
                    Exception error = null;
                    try
                    {
                        if (await aS.CheckIfStillValidAsync())
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return(true);
                        }
                    }
                    catch (WebTransferException e)
                    {
                        HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e);
                        error = e;
                    }
                    if (error != null)
                    {
                        if (AuthValidationMode.Graceful.Equals(validationMode))
                        {
                            _authStatus = aS;
                            ExecuteSuccessRedirectOrAction();
                            return(true);
                        }
                        else
                        {
                            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                            {
                                await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                            });
                        }
                    }
                }
                else
                {
                    if (AuthValidationMode.Graceful.Equals(validationMode))
                    {
                        ExecuteSuccessRedirectOrAction();
                        return(true);
                    }
                    else
                    {
                        await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            await new MessageDialog(LocalizedStrings.LocalizedResources.AuthNetworkError).ShowAsync();
                        });
                    }
                }
            }
            return(false);
        }