Skip to content

Commit 60b2916

Browse files
committed
github: use localhost redirect URI for GHES instances
For GitHub.com we've updated the redirect URI to 127.0.0.1, whilst also keeping the localhost variant around for backwards compatibility with older GCM clients. However, since GHES has not been updated with the new 127.0.0.1 redirect, and older GHES servers will be stuck with the old redirect we must continue to use the localhost redirect on the client for non-dotcom targets.
1 parent 397f05d commit 60b2916

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/shared/GitHub/GitHubConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class GitHubConstants
1616
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="OAuth2 public client application 'secrets' are required and permitted to be public")]
1717
public const string OAuthClientSecret = "18867509d956965542b521a529a79bb883344c90";
1818
public static readonly Uri OAuthRedirectUri = new Uri("http://127.0.0.1/"); // Note that the trailing slash is important!
19+
public static readonly Uri OAuthLegacyRedirectUri = new Uri("http://localhost/"); // Note that the trailing slash is important!
1920
public static readonly Uri OAuthAuthorizationEndpointRelativeUri = new Uri("/login/oauth/authorize", UriKind.Relative);
2021
public static readonly Uri OAuthTokenEndpointRelativeUri = new Uri("/login/oauth/access_token", UriKind.Relative);
2122
public static readonly Uri OAuthDeviceEndpointRelativeUri = new Uri("/login/device/code", UriKind.Relative);

src/shared/GitHub/GitHubOAuth2Client.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class GitHubOAuth2Client : OAuth2Client
99
{
1010
public GitHubOAuth2Client(HttpClient httpClient, ISettings settings, Uri baseUri, ITrace2 trace2)
1111
: base(httpClient, CreateEndpoints(baseUri),
12-
GetClientId(settings), trace2, GetRedirectUri(settings), GetClientSecret(settings)) { }
12+
GetClientId(settings), trace2, GetRedirectUri(settings, baseUri), GetClientSecret(settings)) { }
1313

1414
private static OAuth2ServerEndpoints CreateEndpoints(Uri baseUri)
1515
{
@@ -37,7 +37,7 @@ private static string GetClientId(ISettings settings)
3737
return GitHubConstants.OAuthClientId;
3838
}
3939

40-
private static Uri GetRedirectUri(ISettings settings)
40+
private static Uri GetRedirectUri(ISettings settings, Uri targetUri)
4141
{
4242
// Check for developer override value
4343
if (settings.TryGetSetting(
@@ -48,7 +48,10 @@ private static Uri GetRedirectUri(ISettings settings)
4848
return redirectUri;
4949
}
5050

51-
return GitHubConstants.OAuthRedirectUri;
51+
// Only GitHub.com supports the new OAuth redirect URI today
52+
return GitHubHostProvider.IsGitHubDotCom(targetUri)
53+
? GitHubConstants.OAuthRedirectUri
54+
: GitHubConstants.OAuthLegacyRedirectUri;
5255
}
5356

5457
private static string GetClientSecret(ISettings settings)

0 commit comments

Comments
 (0)