Beispiel #1
0
        /// <summary>
        /// Dokonuje logowania przy użyciu Microsoft (Oauth 2)
        /// </summary>
        public async Task AuthenticateWithMicrosoftAsync()
        {
            try
            {
                IsAuthenticationButtonsEnabled = false;
                AuthenticationProcessor authentication = new AuthenticationProcessor();
                UserPublic userAccount = await authentication.AuthenticateAsync(AuthenticationProvider.Microsoft, mCancellationToken.Token).ConfigureAwait(false);

                if (this.ValidateAccount(userAccount, AuthenticationProvider.Microsoft))
                {
                    await LoginUserPTM().ConfigureAwait(false);

                    await this.OpenMainWindowAsync().ConfigureAwait(false);
                }
            }
            catch (OperationCanceledException)
            {
                // do nothing
            }
            catch (Exception ex)
            {
                mContext.DialogBuilder.ErrorDialog((Application.Current.TryFindResource("IDS_LoginWindow_AuthenticationError") as string), ex);
            }
            finally
            {
                IsAuthenticationButtonsEnabled = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Dokonuje próby logowania, jeżeli zapisane jest poprzednie logowanie
        /// </summary>
        public async Task LoginOnStartup()
        {
            SettingsManager settingsManager = new SettingsManager();
            string          defaultProvider = settingsManager.LoadProvider();

            if (!string.IsNullOrEmpty(defaultProvider))
            {
                if (Enum.TryParse(typeof(AuthenticationProvider), defaultProvider, out object provider))
                {
                    IsAuthenticationButtonsEnabled = false;
                    AuthenticationProvider authProvider = (AuthenticationProvider)provider;

                    AuthenticationProcessor authentication = new AuthenticationProcessor();
                    UserPublic userAccount = await authentication.AuthenticateAsync(authProvider, mCancellationToken.Token).ConfigureAwait(false);

                    if (this.ValidateAccount(userAccount, authProvider))
                    {
                        await LoginUserPTM().ConfigureAwait(false);

                        await this.OpenMainWindowAsync().ConfigureAwait(false);

                        return;
                    }

                    IsAuthenticationButtonsEnabled = true;
                }
            }
            else
            {
                settingsManager.DeleteProvider();
            }

            // Jeśli nie udało się zweryfikować usera, to pokazujemy okno
            mContext.WindowManager.ActivateWindow(Identity);
        }
        public async Task AuthenticateAsync_OnGoogleRefreshToken_SuccessfulAuthentication()
        {
            // ARRANGE
            AuthenticationProcessor processor = new AuthenticationProcessor();
            CredentialsManager      manager   = new CredentialsManager(AuthenticationProvider.Google);

            manager.SaveToken("*TOKEN*");

            // ACT
            UserPublic account = await processor.AuthenticateAsync(AuthenticationProvider.Google, CancellationToken.None);

            // ASSERT
            account.Should().NotBeNull();

            manager.DeleteToken();
        }