Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit GitHub device code authentication option #478

Merged
merged 5 commits into from
Oct 7, 2021

Conversation

mjcheetham
Copy link
Collaborator

Implement an explicit OAuth device code authentication mode for the GitHub host provider. Previously the 'web browser' option combined both the interactive/browser based flow (when a UI was present), and a TTY-based device code flow.

This change allows users to select the device code flow even when they have a desktop/UI session present. This is useful to workaround possible problems with the browser loopback/redirect mechanism.

As well as introducing new "browser" and "device" values, we keep the existing "oauth" value for the GCM_GITHUB_AUTHMODES environment variable and credential.gitHubAuthModes Git config, and let it expand to both browser and device to allow users who may have set the older value before.

- Avalonia
(macOS)
Avalonia
(Ubuntu)
WPF
(Windows)
GUI Prompt image image image
GUI Code Display image image image
Terminal image image image

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.
Consolidate all the UI helper options for the GitHub `prompt` view in to
an `Options` class (rather than bloat the execution handler with more
arguments).

Also fix a bug whereby the GitHub host provider would attempt to invoke
the UI helper with an `--all` option when all authentication modes are
available, but no such option is available!

This option was only available on the old WPF UI helper, and was never
carried forward to the Avalonia UI.
Copy link
Contributor

@vtbassmatt vtbassmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Implement an explicit OAuth device code authentication mode for the
GitHub host provider. Previously the 'web browser' option combined both
the interactive/browser based flow (when a UI was present), and a
TTY-based device code flow.

This change allows users to select the device code flow even when they
have a desktop/UI session present. This is useful to workaround possible
problems with the browser loopback/redirect mechanism.
Add the device code option to the Avalonia and WPF helper UI
applications for GitHub.

This includes adding a new explicit "device code" button to the
primary authentication prompt view, and a new device code display
prompt.
Update documentation to include the new `browser` and `device`
authentication modes for GitHub. The old `oauth` value expands to both
`browser, device` for compatibility.
@@ -121,7 +121,7 @@ public async Task GitHubHostProvider_GetSupportedAuthenticationModes(string uriS
[Theory]
[InlineData("https://example.com", null, "0.1", false, AuthenticationModes.Pat)]
[InlineData("https://example.com", null, "0.1", true, AuthenticationModes.Basic | AuthenticationModes.Pat)]
[InlineData("https://example.com", null, "100.0", false, AuthenticationModes.Browser | AuthenticationModes.Pat)]
[InlineData("https://example.com", null, "100.0", false, AuthenticationModes.OAuth | AuthenticationModes.Pat)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an errant revert of a previous change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. OAuth is the combination of two. Should we have lines for Browser, Device, and OAuth on this test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change is to rename the current (browser) behaviour to Browser, to better reflect what that mode does.
The next change is to add a new Device mode, and reuse the newly "freed" option of OAuth to represent the combination of Browser and Device.

This test checks that a GHES instance with version number 100.0 should support both Browser and Device(i.e, OAuth).

@@ -196,7 +196,7 @@ public async Task GitHubHostProvider_GenerateCredentialAsync_Browser_ReturnsCred
ghAuthMock.Setup(x => x.GetAuthenticationAsync(expectedTargetUri, null, It.IsAny<AuthenticationModes>()))
.ReturnsAsync(new AuthenticationPromptResult(AuthenticationModes.Browser));

ghAuthMock.Setup(x => x.GetOAuthTokenAsync(expectedTargetUri, It.IsAny<IEnumerable<string>>()))
ghAuthMock.Setup(x => x.GetOAuthTokenViaBrowserAsync(expectedTargetUri, It.IsAny<IEnumerable<string>>()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the message for this commit, you say

This is useful to workaround possible
problems with the browser loopback/redirect mechanism.

Do you have an example? I'm guessing WSL has something to do with this.

Copy link
Collaborator Author

@mjcheetham mjcheetham Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed one, but the one that jumps to mind is problems we've had with:

  • AVs blocking loopback listening
  • enterprises that have registered localhost as a valid name with their DNS nameservers (yes, it has happened!!)
  • There are some random 'failures' that other teams have not been able to diagnose

See these issues the GitHub VS Extension has had problems with the loopback mechanism before:

@mjcheetham mjcheetham merged commit 3d8c319 into git-ecosystem:main Oct 7, 2021
@mjcheetham mjcheetham deleted the gh-device-ui branch October 7, 2021 08:59
@mjcheetham mjcheetham mentioned this pull request Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants