From 4fb0f1c89375928a842e3052f7125637298b39b1 Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Wed, 12 May 2021 18:39:01 +0100 Subject: [PATCH] github: add support for OAuth with GHAE Add support for detecting GitHub AE (GHAE) and enabling the OAuth authentication mode with the GitHub provider. https://docs.github.com/en/github-ae@latest/admin/overview/about-github-ae --- src/shared/GitHub/GitHubConstants.cs | 5 +++++ src/shared/GitHub/GitHubHostProvider.cs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/shared/GitHub/GitHubConstants.cs b/src/shared/GitHub/GitHubConstants.cs index 526b76489..cfe9e3748 100644 --- a/src/shared/GitHub/GitHubConstants.cs +++ b/src/shared/GitHub/GitHubConstants.cs @@ -32,6 +32,11 @@ public static class GitHubConstants // TODO: update this with a real version number once the GCM OAuth application has been deployed to GHE public static readonly Version MinimumEnterpriseOAuthVersion = new Version("99.99.99"); + /// + /// The version string returned from the meta API endpoint for GitHub AE instances. + /// + public const string GitHubAeVersionString = "GitHub AE"; + /// /// Supported authentication modes for GitHub.com. /// diff --git a/src/shared/GitHub/GitHubHostProvider.cs b/src/shared/GitHub/GitHubHostProvider.cs index 606ab878a..05768669b 100644 --- a/src/shared/GitHub/GitHubHostProvider.cs +++ b/src/shared/GitHub/GitHubHostProvider.cs @@ -263,8 +263,15 @@ internal async Task GetSupportedAuthenticationModesAsync(Ur { modes |= AuthenticationModes.Basic; } - if (Version.TryParse(metaInfo.InstalledVersion, out var version) && version >= GitHubConstants.MinimumEnterpriseOAuthVersion) + + if (StringComparer.OrdinalIgnoreCase.Equals(metaInfo.InstalledVersion, GitHubConstants.GitHubAeVersionString)) + { + // Assume all GHAE instances have the GCM OAuth application deployed + modes |= AuthenticationModes.OAuth; + } + else if (Version.TryParse(metaInfo.InstalledVersion, out var version) && version >= GitHubConstants.MinimumEnterpriseOAuthVersion) { + // Only GHES versions beyond the minimum version have the GCM OAuth application deployed modes |= AuthenticationModes.OAuth; }