/// <summary> /// Determines if we currently have a valid Authentication token or if we have an expired Authentication token /// we will attempt to refresh it /// </summary> /// <param name="authTokens">Authentication Token</param> /// <returns>True if we have a valid access token</returns> protected virtual async Task <bool> IsValidAccessToken(IAuthTokens authTokens) { if (IsResourcePassworFlowProvider) { return(true); } if (!string.IsNullOrEmpty(authTokens.AccessToken)) { // Check if it is a valid token var tokenResult = await IntrospectionClient.IsValidToken(authTokens.AccessToken) .ConfigureAwait(false); // If it is not a valid token - has it expired? if (tokenResult == TokenValidationResult.Success) { return(true); } // If it has expired and we have a refresh token, refresh the access token. if (tokenResult == TokenValidationResult.Expired && !string.IsNullOrEmpty(authTokens.RefreshToken)) { return(await RefreshTokens(authTokens).ConfigureAwait(false)); } } return(false); }