Ejemplo n.º 1
0
        private async Task <bool> PerformAuthenticateWithPersonalAccessTokenAsync()
        {
            // check to see if we have a token.
            _logger.LogDebug("Getting personal access token...");
            _token = await _settingsService.GetTokenAsync(TokenTypes.PersonalAccessToken);

            if (_token == null || !_token.IsValid)
            {
                _logger.LogError("No personal token available.");
                IsAuthenticated = false;
                return(false);
            }

            // token is available, attempt to log in with it.
            _logger.LogInformation("Personal access token available. Attempting to login...");
            Status = "Token available. Logging in...";
            AuthenticationResult tokenResult = await _authorizationService.AuthenticateWithPersonalAccessTokenAsync(_token.Token);

            if (!tokenResult.AuthenticationSuccessful)
            {
                // token was invalid
                _logger.LogInformation("Personal access token was invalid.");
                _IsAuthenticated = false;

                // clear token.
                _logger.LogInformation("Clearing Personal access token...");
                await _settingsService.ClearTokenAsync(TokenTypes.PersonalAccessToken);

                return(false);
            }

            return(true);
        }