Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 41e0871

Browse files
committed
Check enterprise version for SSO support.
1 parent 9f98221 commit 41e0871

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/GitHub.Api/SimpleApiClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ public SimpleApiClient(UriString repoUrl, IGitHubClient githubClient,
3838

3939
public IGitHubClient Client { get; }
4040

41-
public Task<Meta> GetMetadata() => Client.Miscellaneous.GetMetadata();
42-
4341
public async Task<Repository> GetRepository()
4442
{
4543
// fast path to avoid locking when the cache has already been set

src/GitHub.App/Services/EnterpriseCapabilitiesService.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace GitHub.Services
1212
[PartCreationPolicy(CreationPolicy.Shared)]
1313
public class EnterpriseCapabilitiesService : IEnterpriseCapabilitiesService
1414
{
15+
static readonly Version MinimumOAuthVersion = new Version("2.12.1");
1516
readonly ISimpleApiClientFactory apiClientFactory;
1617
readonly IEnterpriseProbe probe;
1718

@@ -29,11 +30,17 @@ public EnterpriseCapabilitiesService(
2930
public async Task<EnterpriseLoginMethods> ProbeLoginMethods(Uri enterpriseBaseUrl)
3031
{
3132
var result = EnterpriseLoginMethods.Token;
32-
var client = await apiClientFactory.Create(UriString.ToUriString(enterpriseBaseUrl));
33-
var meta = await client.GetMetadata();
33+
var client = await apiClientFactory.Create(UriString.ToUriString(enterpriseBaseUrl)).ConfigureAwait(false);
34+
var meta = await GetMetadata(client.Client).ConfigureAwait(false);
3435

3536
if (meta.VerifiablePasswordAuthentication) result |= EnterpriseLoginMethods.UsernameAndPassword;
3637

38+
if (meta.InstalledVersion != null)
39+
{
40+
var version = new Version(meta.InstalledVersion);
41+
if (version >= MinimumOAuthVersion) result |= EnterpriseLoginMethods.OAuth;
42+
}
43+
3744
return result;
3845
}
3946

@@ -49,5 +56,17 @@ private Uri GetLoginUrl(IConnection connection)
4956
// OauthClient.GetGitHubLoginUrl seems to give the wrong URL. Fix this.
5057
return new Uri(uri.ToString().Replace("/api/v3", ""));
5158
}
59+
60+
private async Task<EnterpriseMeta> GetMetadata(IGitHubClient client)
61+
{
62+
var endpoint = new Uri("meta", UriKind.Relative);
63+
var response = await client.Connection.Get<EnterpriseMeta>(endpoint, null, null).ConfigureAwait(false);
64+
return response.Body;
65+
}
66+
67+
class EnterpriseMeta : Meta
68+
{
69+
public string InstalledVersion { get; private set; }
70+
}
5271
}
5372
}

src/GitHub.Exports/Api/ISimpleApiClient.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public interface ISimpleApiClient
99
IGitHubClient Client { get; }
1010
HostAddress HostAddress { get; }
1111
UriString OriginalUrl { get; }
12-
Task<Meta> GetMetadata();
1312
Task<Repository> GetRepository();
1413
bool HasWiki();
1514
bool IsEnterprise();

0 commit comments

Comments
 (0)