2using System.Globalization;
4using System.Threading.Tasks;
6using Microsoft.Extensions.Logging;
35 readonly ILogger<GitHubOAuthValidator>
logger;
50 ILogger<GitHubOAuthValidator>
logger,
54 this.logger =
logger ??
throw new ArgumentNullException(nameof(
logger));
59 public async ValueTask<(
string? UserID,
string AccessCode)?>
ValidateResponseCode(
string code,
bool requireUserID, CancellationToken cancellationToken)
61 ArgumentNullException.ThrowIfNull(code);
65 logger.LogTrace(
"Validating response code...");
68 var token = await gitHubService.CreateOAuthAccessToken(
oAuthConfiguration, code, cancellationToken);
73 return (
null, AccessCode: token);
77 logger.LogTrace(
"Getting user details...");
78 var userId = await authenticatedClient.GetCurrentUserId(cancellationToken);
80 return (userId.ToString(CultureInfo.InvariantCulture), AccessCode: token);
82 catch (RateLimitExceededException)
86 catch (ApiException ex)
88 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.
OAuthGatewayStatus GatewayStatus
The OAuthGatewayStatus for the IOAuthValidator.
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.
readonly OAuthConfiguration oAuthConfiguration
The OAuthConfiguration for the GitHubOAuthValidator.
async ValueTask<(string? UserID, string AccessCode)?> ValidateResponseCode(string code, bool requireUserID, CancellationToken cancellationToken)
Validate a given OAuth response code .A ValueTask<TResult> resulting in null if authentication failed...
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.
ValueTask< IGitHubService > CreateService(CancellationToken cancellationToken)
Create a IGitHubService.
OAuthProvider
List of OAuth providers supported by TGS.
OAuthGatewayStatus
Status of the OAuth gateway for a provider.