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!");
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 ValueTask< string?> ValidateResponseCode(string code, CancellationToken cancellationToken)
Validate a given OAuth response code . A ValueTask<TResult> resulting in null if authentication faile...
readonly OAuthConfiguration oAuthConfiguration
The OAuthConfiguration for the GitHubOAuthValidator.
OAuthProviderInfo GetProviderInfo()
Gets the OAuthProvider of validator. The client ID of the validator on success, null on failure.
Validates OAuth responses for a given Provider.
Factory for IGitHubServices.
IGitHubService CreateService()
Create a IGitHubService.
ValueTask< 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.