Skip to content

Commit 24356dc

Browse files
committed
github: rename OAuth authmode to Browser
Rename the OAuth GitHub authentication mode to Browser to better match what interaction will happen when selecting this mode. Also prepare for the introduction of an explicit device code OAuth flow mode.
1 parent 613d894 commit 24356dc

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/shared/GitHub.Tests/GitHubHostProviderTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void GitHubHostProvider_GetCredentialServiceUrl(string protocol, string h
9292

9393

9494
[Theory]
95-
[InlineData("https://example.com", "oauth", AuthenticationModes.OAuth)]
95+
[InlineData("https://example.com", "browser", AuthenticationModes.Browser)]
9696
[InlineData("https://github.com", "NOT-A-REAL-VALUE", GitHubConstants.DotComAuthenticationModes)]
9797
[InlineData("https://GitHub.Com", "NOT-A-REAL-VALUE", GitHubConstants.DotComAuthenticationModes)]
9898
[InlineData("https://github.com", "none", GitHubConstants.DotComAuthenticationModes)]
@@ -121,7 +121,7 @@ public async Task GitHubHostProvider_GetSupportedAuthenticationModes(string uriS
121121
[Theory]
122122
[InlineData("https://example.com", null, "0.1", false, AuthenticationModes.Pat)]
123123
[InlineData("https://example.com", null, "0.1", true, AuthenticationModes.Basic | AuthenticationModes.Pat)]
124-
[InlineData("https://example.com", null, "100.0", false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
124+
[InlineData("https://example.com", null, "100.0", false, AuthenticationModes.Browser | AuthenticationModes.Pat)]
125125
[InlineData("https://example.com", null, "100.0", true, AuthenticationModes.All)]
126126
public async Task GitHubHostProvider_GetSupportedAuthenticationModes_WithMetadata(string uriString, string gitHubAuthModes,
127127
string installedVersion, bool verifiablePasswordAuthentication, AuthenticationModes expectedModes)
@@ -170,7 +170,7 @@ public async Task GitHubHostProvider_GenerateCredentialAsync_UnencryptedHttp_Thr
170170
}
171171

172172
[Fact]
173-
public async Task GitHubHostProvider_GenerateCredentialAsync_OAuth_ReturnsCredential()
173+
public async Task GitHubHostProvider_GenerateCredentialAsync_Browser_ReturnsCredential()
174174
{
175175
var input = new InputArguments(new Dictionary<string, string>
176176
{
@@ -194,7 +194,7 @@ public async Task GitHubHostProvider_GenerateCredentialAsync_OAuth_ReturnsCreden
194194

195195
var ghAuthMock = new Mock<IGitHubAuthentication>(MockBehavior.Strict);
196196
ghAuthMock.Setup(x => x.GetAuthenticationAsync(expectedTargetUri, null, It.IsAny<AuthenticationModes>()))
197-
.ReturnsAsync(new AuthenticationPromptResult(AuthenticationModes.OAuth));
197+
.ReturnsAsync(new AuthenticationPromptResult(AuthenticationModes.Browser));
198198

199199
ghAuthMock.Setup(x => x.GetOAuthTokenAsync(expectedTargetUri, It.IsAny<IEnumerable<string>>()))
200200
.ReturnsAsync(response);

src/shared/GitHub.UI/Commands/CredentialsCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected CredentialsCommand(ICommandContext context)
2828
);
2929

3030
AddOption(
31-
new Option("--oauth", "Enable browser-based OAuth authentication.")
31+
new Option("--browser", "Enable browser-based OAuth authentication.")
3232
);
3333

3434
AddOption(
@@ -38,11 +38,11 @@ protected CredentialsCommand(ICommandContext context)
3838
Handler = CommandHandler.Create<string, string, bool, bool, bool>(ExecuteAsync);
3939
}
4040

41-
private async Task<int> ExecuteAsync(string enterpriseUrl, string userName, bool basic, bool oauth, bool pat)
41+
private async Task<int> ExecuteAsync(string enterpriseUrl, string userName, bool basic, bool browser, bool pat)
4242
{
4343
var viewModel = new CredentialsViewModel(Context.Environment)
4444
{
45-
ShowBrowserLogin = oauth,
45+
ShowBrowserLogin = browser,
4646
ShowTokenLogin = pat,
4747
ShowBasicLogin = basic,
4848
};
@@ -74,8 +74,8 @@ private async Task<int> ExecuteAsync(string enterpriseUrl, string userName, bool
7474
result["password"] = viewModel.Password;
7575
break;
7676

77-
case AuthenticationModes.OAuth:
78-
result["mode"] = "oauth";
77+
case AuthenticationModes.Browser:
78+
result["mode"] = "browser";
7979
break;
8080

8181
case AuthenticationModes.Pat:

src/shared/GitHub.UI/ViewModels/CredentialsViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void SignUp()
6464

6565
private void SignInBrowser()
6666
{
67-
SelectedMode = AuthenticationModes.OAuth;
67+
SelectedMode = AuthenticationModes.Browser;
6868
Accept();
6969
}
7070

src/shared/GitHub/GitHubAuthentication.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public enum AuthenticationModes
4242
{
4343
None = 0,
4444
Basic = 1,
45-
OAuth = 1 << 1,
45+
Browser = 1 << 1,
4646
Pat = 1 << 2,
4747

48-
All = Basic | OAuth | Pat
48+
All = Basic | Browser | Pat
4949
}
5050

5151
public class GitHubAuthentication : AuthenticationBase, IGitHubAuthentication
@@ -76,9 +76,9 @@ public async Task<AuthenticationPromptResult> GetAuthenticationAsync(Uri targetU
7676
}
7777
else
7878
{
79-
if ((modes & AuthenticationModes.Basic) != 0) promptArgs.Append(" --basic");
80-
if ((modes & AuthenticationModes.OAuth) != 0) promptArgs.Append(" --oauth");
81-
if ((modes & AuthenticationModes.Pat) != 0) promptArgs.Append(" --pat");
79+
if ((modes & AuthenticationModes.Basic) != 0) promptArgs.Append(" --basic");
80+
if ((modes & AuthenticationModes.Browser) != 0) promptArgs.Append(" --browser");
81+
if ((modes & AuthenticationModes.Pat) != 0) promptArgs.Append(" --pat");
8282
}
8383
if (!GitHubHostProvider.IsGitHubDotCom(targetUri)) promptArgs.AppendFormat(" --enterprise-url {0}", QuoteCmdArg(targetUri.ToString()));
8484
if (!string.IsNullOrWhiteSpace(userName)) promptArgs.AppendFormat(" --username {0}", QuoteCmdArg(userName));
@@ -101,8 +101,8 @@ public async Task<AuthenticationPromptResult> GetAuthenticationAsync(Uri targetU
101101
return new AuthenticationPromptResult(
102102
AuthenticationModes.Pat, new GitCredential(userName, pat));
103103

104-
case "oauth":
105-
return new AuthenticationPromptResult(AuthenticationModes.OAuth);
104+
case "browser":
105+
return new AuthenticationPromptResult(AuthenticationModes.Browser);
106106

107107
case "basic":
108108
if (!resultDict.TryGetValue("username", out userName))
@@ -145,8 +145,8 @@ public async Task<AuthenticationPromptResult> GetAuthenticationAsync(Uri targetU
145145
return new AuthenticationPromptResult(
146146
AuthenticationModes.Basic, new GitCredential(userName, password));
147147

148-
case AuthenticationModes.OAuth:
149-
return new AuthenticationPromptResult(AuthenticationModes.OAuth);
148+
case AuthenticationModes.Browser:
149+
return new AuthenticationPromptResult(AuthenticationModes.Browser);
150150

151151
case AuthenticationModes.Pat:
152152
Context.Terminal.WriteLine("Enter GitHub personal access token for '{0}'...", targetUri);
@@ -161,20 +161,20 @@ public async Task<AuthenticationPromptResult> GetAuthenticationAsync(Uri targetU
161161
var menuTitle = $"Select an authentication method for '{targetUri}'";
162162
var menu = new TerminalMenu(Context.Terminal, menuTitle);
163163

164-
TerminalMenuItem oauthItem = null;
164+
TerminalMenuItem browserItem = null;
165165
TerminalMenuItem basicItem = null;
166166
TerminalMenuItem patItem = null;
167167

168-
if ((modes & AuthenticationModes.OAuth) != 0) oauthItem = menu.Add("Web browser");
169-
if ((modes & AuthenticationModes.Pat) != 0) patItem = menu.Add("Personal access token");
170-
if ((modes & AuthenticationModes.Basic) != 0) basicItem = menu.Add("Username/password");
168+
if ((modes & AuthenticationModes.Browser) != 0) browserItem = menu.Add("Web browser");
169+
if ((modes & AuthenticationModes.Pat) != 0) patItem = menu.Add("Personal access token");
170+
if ((modes & AuthenticationModes.Basic) != 0) basicItem = menu.Add("Username/password");
171171

172172
// Default to the 'first' choice in the menu
173173
TerminalMenuItem choice = menu.Show(0);
174174

175-
if (choice == oauthItem) goto case AuthenticationModes.OAuth;
176-
if (choice == basicItem) goto case AuthenticationModes.Basic;
177-
if (choice == patItem) goto case AuthenticationModes.Pat;
175+
if (choice == browserItem) goto case AuthenticationModes.Browser;
176+
if (choice == basicItem) goto case AuthenticationModes.Basic;
177+
if (choice == patItem) goto case AuthenticationModes.Pat;
178178

179179
throw new Exception();
180180
}

src/shared/GitHub/GitHubConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static class GitHubConstants
4141
/// As of 13th November 2020, GitHub.com does not support username/password (basic) authentication to the APIs.
4242
/// See https://developer.github.com/changes/2020-02-14-deprecating-oauth-auth-endpoint for more information.
4343
/// </remarks>
44-
public const AuthenticationModes DotComAuthenticationModes = AuthenticationModes.OAuth | AuthenticationModes.Pat;
44+
public const AuthenticationModes DotComAuthenticationModes = AuthenticationModes.Browser | AuthenticationModes.Pat;
4545

4646
public static class TokenScopes
4747
{

src/shared/GitHub/GitHubHostProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public override async Task<ICredential> GenerateCredentialAsync(InputArguments i
149149
Context.CredentialStore.AddOrUpdate(service, patCredential.Account, patCredential.Password);
150150
return patCredential;
151151

152-
case AuthenticationModes.OAuth:
152+
case AuthenticationModes.Browser:
153153
return await GenerateOAuthCredentialAsync(remoteUri);
154154

155155
case AuthenticationModes.Pat:
@@ -267,12 +267,12 @@ internal async Task<AuthenticationModes> GetSupportedAuthenticationModesAsync(Ur
267267
if (StringComparer.OrdinalIgnoreCase.Equals(metaInfo.InstalledVersion, GitHubConstants.GitHubAeVersionString))
268268
{
269269
// Assume all GHAE instances have the GCM OAuth application deployed
270-
modes |= AuthenticationModes.OAuth;
270+
modes |= AuthenticationModes.Browser;
271271
}
272272
else if (Version.TryParse(metaInfo.InstalledVersion, out var version) && version >= GitHubConstants.MinimumOnPremOAuthVersion)
273273
{
274274
// Only GHES versions beyond the minimum version have the GCM OAuth application deployed
275-
modes |= AuthenticationModes.OAuth;
275+
modes |= AuthenticationModes.Browser;
276276
}
277277

278278
Context.Trace.WriteLine($"GitHub Enterprise instance has version '{metaInfo.InstalledVersion}' and supports authentication schemes: {modes}");

0 commit comments

Comments
 (0)