@@ -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}
0 commit comments