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

Commit b6cb68e

Browse files
committed
Assume enterprise user/pass login available.
If the enterprise server doesn't return a value for `VerifiablePasswordAuthentication`, or the `api/meta` endpoint fails completely then we're on an older version of enterprise. In this case assume username and password login is available as we have no way to tell. Fixes #1474
1 parent e948cca commit b6cb68e

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/GitHub.App/Services/EnterpriseCapabilitiesService.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,29 @@ public EnterpriseCapabilitiesService(
3030

3131
public async Task<EnterpriseLoginMethods> ProbeLoginMethods(Uri enterpriseBaseUrl)
3232
{
33-
// It's important that we don't use our cached credentials on this connection, as they
34-
// may be wrong - we're trying to log in after all.
35-
var hostAddress = HostAddress.Create(enterpriseBaseUrl);
36-
var connection = new Octokit.Connection(program.ProductHeader, hostAddress.ApiUri);
37-
var meta = await GetMetadata(connection).ConfigureAwait(false);
38-
var result = EnterpriseLoginMethods.Token;
33+
try
34+
{
35+
// It's important that we don't use our cached credentials on this connection, as they
36+
// may be wrong - we're trying to log in after all.
37+
var hostAddress = HostAddress.Create(enterpriseBaseUrl);
38+
var connection = new Octokit.Connection(program.ProductHeader, hostAddress.ApiUri);
39+
var meta = await GetMetadata(connection).ConfigureAwait(false);
40+
var result = EnterpriseLoginMethods.Token;
41+
42+
if (meta.VerifiablePasswordAuthentication != false) result |= EnterpriseLoginMethods.UsernameAndPassword;
3943

40-
if (meta.VerifiablePasswordAuthentication) result |= EnterpriseLoginMethods.UsernameAndPassword;
44+
if (meta.InstalledVersion != null)
45+
{
46+
var version = new Version(meta.InstalledVersion);
47+
if (version >= MinimumOAuthVersion) result |= EnterpriseLoginMethods.OAuth;
48+
}
4149

42-
if (meta.InstalledVersion != null)
50+
return result;
51+
}
52+
catch
4353
{
44-
var version = new Version(meta.InstalledVersion);
45-
if (version >= MinimumOAuthVersion) result |= EnterpriseLoginMethods.OAuth;
54+
return EnterpriseLoginMethods.Token | EnterpriseLoginMethods.UsernameAndPassword;
4655
}
47-
48-
return result;
4956
}
5057

5158
private async Task<EnterpriseMeta> GetMetadata(IConnection connection)
@@ -56,9 +63,10 @@ private async Task<EnterpriseMeta> GetMetadata(IConnection connection)
5663
}
5764

5865
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Created via Octokit reflection")]
59-
class EnterpriseMeta : Meta
66+
class EnterpriseMeta
6067
{
6168
public string InstalledVersion { get; private set; }
69+
public bool? VerifiablePasswordAuthentication { get; private set; }
6270
}
6371
}
6472
}

src/GitHub.App/ViewModels/Dialog/LoginToGitHubForEnterpriseViewModel.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,14 @@ async void EnterpriseUrlChanged(string url, bool valid)
140140

141141
var enterpriseInstance = false;
142142
var loginMethods = (EnterpriseLoginMethods?)null;
143+
var uri = new UriBuilder(url).Uri;
143144

144-
try
145-
{
146-
var uri = new UriBuilder(url).Uri;
147-
ProbeStatus = EnterpriseProbeStatus.Checking;
145+
ProbeStatus = EnterpriseProbeStatus.Checking;
148146

149-
if (await enterpriseCapabilities.Probe(uri) == EnterpriseProbeResult.Ok)
150-
{
151-
loginMethods = await enterpriseCapabilities.ProbeLoginMethods(uri);
152-
enterpriseInstance = true;
153-
}
154-
}
155-
catch
147+
if (await enterpriseCapabilities.Probe(uri) == EnterpriseProbeResult.Ok)
156148
{
157-
ProbeStatus = EnterpriseProbeStatus.Invalid;
158-
loginMethods = null;
149+
loginMethods = await enterpriseCapabilities.ProbeLoginMethods(uri);
150+
enterpriseInstance = true;
159151
}
160152

161153
if (url == EnterpriseUrl)

0 commit comments

Comments
 (0)