Skip to content

Commit a961eac

Browse files
committed
github: enterprise instances w/ null ver support OAuth
Enterprise instances that return a null version are considered to support OAuth.
1 parent c12409f commit a961eac

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/shared/GitHub.Tests/GitHubHostProviderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ public async Task GitHubHostProvider_GetSupportedAuthenticationModes(string uriS
117117
Assert.Equal(expectedModes, actualModes);
118118
}
119119

120-
121120
[Theory]
122121
[InlineData("https://example.com", null, "0.1", false, AuthenticationModes.Pat)]
123122
[InlineData("https://example.com", null, "0.1", true, AuthenticationModes.Basic | AuthenticationModes.Pat)]
124123
[InlineData("https://example.com", null, "100.0", false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
125124
[InlineData("https://example.com", null, "100.0", true, AuthenticationModes.All)]
125+
[InlineData("https://example.com", null, null, false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
126+
[InlineData("https://example.com", null, "", false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
127+
[InlineData("https://example.com", null, " ", false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
126128
public async Task GitHubHostProvider_GetSupportedAuthenticationModes_WithMetadata(string uriString, string gitHubAuthModes,
127129
string installedVersion, bool verifiablePasswordAuthentication, AuthenticationModes expectedModes)
128130
{
@@ -149,8 +151,6 @@ public async Task GitHubHostProvider_GetSupportedAuthenticationModes_WithMetadat
149151
Assert.Equal(expectedModes, actualModes);
150152
}
151153

152-
153-
154154
[Fact]
155155
public async Task GitHubHostProvider_GenerateCredentialAsync_UnencryptedHttp_ThrowsException()
156156
{

src/shared/GitHub/GitHubConstants.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public static class GitHubConstants
3030
/// </summary>
3131
public static readonly Version MinimumOnPremOAuthVersion = new Version("3.2");
3232

33-
/// <summary>
34-
/// The version string returned from the meta API endpoint for GitHub AE instances.
35-
/// </summary>
36-
public const string GitHubAeVersionString = "GitHub AE";
37-
3833
/// <summary>
3934
/// Supported authentication modes for GitHub.com.
4035
/// </summary>

src/shared/GitHub/GitHubHostProvider.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,20 @@ internal async Task<AuthenticationModes> GetSupportedAuthenticationModesAsync(Ur
263263
{
264264
GitHubMetaInfo metaInfo = await _gitHubApi.GetMetaInfoAsync(targetUri);
265265

266+
// All Enterprise/AE instances support PATs
266267
var modes = AuthenticationModes.Pat;
268+
269+
// If the server says it supports basic auth, we can use that too!
267270
if (metaInfo.VerifiablePasswordAuthentication)
268271
{
269272
modes |= AuthenticationModes.Basic;
270273
}
271274

272-
if (StringComparer.OrdinalIgnoreCase.Equals(metaInfo.InstalledVersion, GitHubConstants.GitHubAeVersionString))
273-
{
274-
// Assume all GHAE instances have the GCM OAuth application deployed
275-
modes |= AuthenticationModes.OAuth;
276-
}
277-
else if (Version.TryParse(metaInfo.InstalledVersion, out var version) && version >= GitHubConstants.MinimumOnPremOAuthVersion)
275+
// If the version is unknown, we *assume* it supports OAuth.
276+
// If the server version at least the minimum required, we *know* we can use OAuth.
277+
if (!Version.TryParse(metaInfo.InstalledVersion, out var version) ||
278+
version >= GitHubConstants.MinimumOnPremOAuthVersion)
278279
{
279-
// Only GHES versions beyond the minimum version have the GCM OAuth application deployed
280280
modes |= AuthenticationModes.OAuth;
281281
}
282282

0 commit comments

Comments
 (0)