microsoft / vscode-test-web

Node module to help testing VS Code web extensions.
MIT License
59 stars 22 forks source link

Support extension `UriHandler`s #19

Open TylerLeonhardt opened 2 years ago

TylerLeonhardt commented 2 years ago

In a vscode extension you can register a URI handler: https://code.visualstudio.com/api/references/vscode-api#UriHandler

This UriHandler will get invoked when an external webpage redirects into VS Code with the extension identifier specified.

This works in vscode.dev (thanks to @joaomoreno) where the server sets up a well-known route (vscode.dev/callback) that handles requests that will turn around and invoke registered UriHandlers. Note, this works in tandem with vscode.env.openExternal which will give you the exact Uri to redirect into.

vscode-test-web should have a similar capability and I feel like a lot of the logic can be shared.

Additionally, the Microsoft and GitHub auth extensions use UriHandler for logging in so this means that extensions that use our in-box auth extensions can not be tested in vscode-test-web either.

Workaround

Sideloading the extension on vscode.dev works around this and still allows the author to test their extension on web.

aeschli commented 2 years ago

@TylerLeonhardt I'm new to the callback, and don't know how the flow works. I (blindly) adopted what @bpasero did in microsoft/vscode#140329. Can you test it out? (Maybe add some steps so I get an idea how to test it myself)

It's just in source, not yet published -> use yarn link.

If I understand this right, ideally this could go to callback.html and no server code is needed.

bpasero commented 2 years ago

There is still a little server dependency to serve callback.html, replace some variables and set the proper content security policy. But it is true that the change I pushed for callbacks makes the flow state less, where before the server had to keep callbacks in memory (now they are in local storage of the client).

aeschli commented 2 years ago

In the meantime we've adopted the new fully serverless callback.html.

@TylerLeonhardt Is the more needed to get the auth flow running in vscode-test-web as well?

Currently, when I try the github authentication flow, I end up with the Enter Github Auth Token quick input.

TylerLeonhardt commented 2 years ago

@aeschli GitHub auth doesn't work with localhost. You will have to try either Microsoft auth or I made a test extension for UriHandlers: https://github.com/TylerLeonhardt/open-external

once you have it running locally, run the command: Open an external Uri and choose Trigger uri handler...