private async Task <bool> PerformAuthenticateWithTokenAsync() { // check to see if we have a token. _logger.LogDebug("Getting token..."); _token = await _settingsService.GetTokenAsync(TokenTypes.AuthorizationToken); if (_token == null || !_token.IsValid) { _logger.LogError("No token available."); IsAuthenticated = false; return(false); } // token is available, attempt to log in with it. _logger.LogInformation("Token available. Attempting to login..."); Status = "Token available. Logging in..."; AuthenticationResult tokenResult = await _authorizationService.AuthenticateWithTokenAsync(_token.Token); if (!tokenResult.AuthenticationSuccessful) { // token was invalid _logger.LogInformation("Token was invalid."); _IsAuthenticated = false; // clear token. _logger.LogInformation("Clearing Token..."); await _settingsService.ClearTokenAsync(TokenTypes.AuthorizationToken); return(false); } return(true); }
private async Task AuthenticateWithTokenAsync() { bool isValidToken = false; try { Status = "Attempting to authenticate with token..."; _logger.LogInformation("Authenticating with token..."); AuthenticationResult result = await _authorizationService.AuthenticateWithTokenAsync(Token); isValidToken = result.AuthenticationSuccessful; } catch (Exception ex) { _logger.LogError(ex, "Error authenticating with token."); Status = "There was an error authenticating with the token: " + ex.Message; } if (isValidToken) { await _navigationService.NavigateToAsync <HomeViewModel>(addtoStack : false); } }