theia icon indicating copy to clipboard operation
theia copied to clipboard

Cannot "Connect to Github"

Open tsmaeder opened this issue 1 year ago • 17 comments

The very useful Gitlens extensions offers to "Connect to Github" in order to directly jump to the relevant PR on github from an editor hover. This simply does not work.

To Reproduce

  1. Install gitlens
  2. Open an editor on a file in a github repo, for example theia itself.
  3. When you hover at the end of a line, you get a hover that shows you information about the commit that last changed this line.
  4. Scroll to the bottom of the hover
  5. Observe: there is a link that says "Connect to Github".
  6. Click the link
  7. Observe: nothing happens (not even messages in the browser log) My expectation would be that I would be taken through github authentication and then back to see links to PR's in the hover.

tsmaeder avatar Aug 10 '23 09:08 tsmaeder

@tsmaeder it perhaps relies on the vscode.github and vscode.github-authentication builtin plugins which are not included in blueprint?

vince-fugnitto avatar Aug 10 '23 11:08 vince-fugnitto

That is entirely possible. Any reason why we're not including all the built-ins from VS Code?

tsmaeder avatar Aug 10 '23 11:08 tsmaeder

Even with those extensions installed, The sign-in fails with Sign in failed: Error: Invalid scheme 'theia'.

tsmaeder avatar Aug 10 '23 11:08 tsmaeder

That is entirely possible. Any reason why we're not including all the built-ins from VS Code?

At least for the main repo they are excluded since they rely on the git builtins. It's possible that it is something that was copied over to blueprint from the main repo.

vince-fugnitto avatar Aug 10 '23 11:08 vince-fugnitto

On vscode, an external browser is opened towards GitHub, when the "Allow" button is pressed.

image

I think this operation fails on Theia because we have a stub for proposed "ExternalUriOpener":

https://github.com/eclipse-theia/theia/blob/master/packages/plugin/src/theia.proposed.externalUriOpener.d.ts

marcdumais-work avatar Aug 10 '23 19:08 marcdumais-work

@JonasHelming I can investigate this

AlexandraBuzila avatar Oct 24 '23 08:10 AlexandraBuzila

Great, I assigned it to you!

JonasHelming avatar Oct 24 '23 08:10 JonasHelming

Status please.

poundjd avatar Oct 24 '23 08:10 poundjd

PR is under review

JonasHelming avatar Nov 17 '23 14:11 JonasHelming

With the gitlens example from the testing instructions in the linked PR, I don't even get the "Connect to Github" link anymore. Reopening.

tsmaeder avatar Apr 10 '24 16:04 tsmaeder

This is weird: when I log out of Github in VS Code, I get the "Connect to Github" link again, but when I click it, nothing happens in the UI: There is an exception caught in the browser debugger:

Error: Timed out waiting for authentication provider to register

This is in TheiaIDE 1.48.300. In master I don't get the link to log in.

tsmaeder avatar Apr 11 '24 08:04 tsmaeder

Turns out TheiaIDE just does not contain github-authentication. The Timeout is a false positive in plugin-authentication-service.ts#tryActivateProvider: we're racing success against timeout, but the timeout never is cancelled.

tsmaeder avatar Apr 11 '24 10:04 tsmaeder

It seems I have a Github session in my Windows Credentials Manager. There is a problem in authentication-ext.ts#registerAuthenticationProvider: when a new registration provider is registered, we add a listener that will notify the front end of any new sessions being created. But the github AuthenticationProvider restores some sessions from the system keychain and those sessions are never communicated to the front end. Therefore, the login would not show up in the "accounts" in the left sidebar (little manikin icon at the bottom). After fixing this problem, I get the "You have not finished authorizing" dialog mentioned in the linked PR. When I click on "yes", I get an error message saying Sign in failed: Error: No auth flow succeeded.. Debugging through the github-authentication extensions, I found two reasons:

  1. The UrlHandlerAuthenticationFlow (the regular flow) is disable, because the extension only allows it for supported clients ('vscode', etc., see https://github.com/microsoft/vscode/blob/013132a5cde7733e8fc59f633c03018ca08db9a1/extensions/github-authentication/src/common/env.ts#L22) 'theia', which comes from the vscode.env.uriScheme is obviously not included.

  2. The "device code" flow fails because it uses the command workbench.getCodeExchangeProxyEndpoints, (via GithubServer.getRedirectEndpoint()) which is a vscode-internal command we don't implement. Note that it's not a command documented in https://code.visualstudio.com/api/references/commands

In short: the gitub-authentication extension relies on VS Code internals and therefore does not work with Theia. Possible workarounds would be to return vscode from vscode.env.uriScheme. Not sure whether that has other unforeseen consequences, though.

tsmaeder avatar Apr 11 '24 13:04 tsmaeder

Hmh...I'm not sure using the UrlHandlerFlow is a good idea anyway: it requires having the github app client secret available to the VS Code app, which is not recommended practice.

tsmaeder avatar Apr 12 '24 08:04 tsmaeder

So even with the scheme changed to vscode, this does not work, since we obviously don't have access to the vscode github app client secret. Not sure how to implement the workbench.getCodeExchangeProxyEndpoints command. I looked for the implementation in VS Code, and it's totally obscure how these get configured. Also, I'm not convinced we are even registered as a url handler for theia://.... anywayy, see https://github.com/eclipse-theia/theia/pull/13306#issuecomment-1910452763

tsmaeder avatar Apr 12 '24 10:04 tsmaeder

Maybe it's simplest to write our own "github" authentication provider?

tsmaeder avatar Apr 12 '24 10:04 tsmaeder

Seems the Electron case (device token flow) is broken again. @JonasHelming.

tsmaeder avatar Jul 18 '24 12:07 tsmaeder

Duh! I had cleaned out my .theia-ide settings folder, including the installed "github-authentication" vscode extension. The workflow works fine 🤷

tsmaeder avatar Aug 02 '24 13:08 tsmaeder

Closing, as this works on the desktop now.

tsmaeder avatar Aug 06 '24 11:08 tsmaeder