2using System.Globalization;
4using System.Threading.Tasks;
6using Microsoft.Extensions.Logging;
31 readonly ILogger<GitHubOAuthValidator>
logger;
46 ILogger<GitHubOAuthValidator>
logger,
50 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
57 ArgumentNullException.ThrowIfNull(code);
61 logger.LogTrace(
"Validating response code...");
70 logger.LogTrace(
"Getting user details...");
71 var userId = await authenticatedClient.GetCurrentUserId(cancellationToken);
73 return userId.ToString(CultureInfo.InvariantCulture);
75 catch (RateLimitExceededException)
79 catch (ApiException ex)
81 logger.LogWarning(ex,
"API error while completing OAuth handshake!");
87 public Task<OAuthProviderInfo>
GetProviderInfo(CancellationToken cancellationToken) => Task.FromResult(
Public information about a given OAuthProvider.
string ClientId
The client ID.
OAuth configuration options.
Uri RedirectUrl
The authentication server URL. Not used by all providers.
IOAuthValidator for GitHub.
GitHubOAuthValidator(IGitHubServiceFactory gitHubServiceFactory, ILogger< GitHubOAuthValidator > logger, OAuthConfiguration oAuthConfiguration)
Initializes a new instance of the GitHubOAuthValidator class.
readonly ILogger< GitHubOAuthValidator > logger
The ILogger for the GitHubOAuthValidator.
OAuthProvider Provider
The OAuthProvider this validator is for.
readonly IGitHubServiceFactory gitHubServiceFactory
The IGitHubServiceFactory for the GitHubOAuthValidator.
async Task< string > ValidateResponseCode(string code, CancellationToken cancellationToken)
Validate a given OAuth response code . A Task<TResult> resulting in null if authentication failed,...
Task< OAuthProviderInfo > GetProviderInfo(CancellationToken cancellationToken)
Gets the OAuthProvider of validator. A Task<TResult> resulting in the client ID of the validator on s...
readonly OAuthConfiguration oAuthConfiguration
The OAuthConfiguration for the GitHubOAuthValidator.
Validates OAuth responses for a given Provider.
Factory for IGitHubServices.
IGitHubService CreateService()
Create a IGitHubService.
Task< string > CreateOAuthAccessToken(OAuthConfiguration oAuthConfiguration, string code, CancellationToken cancellationToken)
Attempt to get an OAuth token from a given code .
OAuthProvider
List of OAuth providers supported by TGS.