Redirect to IDE from browser
Hi,
I'm building an extension which utilizes the PKCE OAuth flow. This means I need to launch out of Intellij and into a browser for sign-on activities, and then redirect back into the IDE to complete the sign-on.
I am able to complete the first step without any issue.
For the second step I need to redirect back from the browser to the IDE - currently I have created a RestService and registered this in the plugin.xml. When I install the plugin manually, I can hit the endpoint. The intension was to call this endpoint as part of the PKCE redirect URL.
However, I would like to redirect back to and regain focus with the IDE (specifically the window that originally launched the browser).
In VSCode this is possible by prefixing the redirect URL with vscode://urlhandleruri and registering a URI handler with a specific authority (the authority is used to determine which instance of VSCode to redirect into).
The browser uses the vscode:// prefix to launch the application, and then the application uses the provided authority to determine which IDE window to focus on.
Can this be recreated in Intellij somehow? Can I launch Intellij from the URL bar within the browser using something like jetbrains://idea/...?
Thanks,
David
Please sign in to leave a comment.
Hi,
I want to provide an update on this as I continue with my investigations on this flow.
I was able to trigger a redirect from Chrome back to Intellij using the following as the redirect URL (I got some ideas from here - https://youtrack.jetbrains.com/issue/IDEA-65879), but the endpoint isn't being executed as I'd hoped.
I can hit my endpoint from postman by issuing a GET request directly to:
However I was hoping that by providing the URL in the following format that Intellij would call my endpoint, but it does not unfortunately.
Could you help me understand if it is possible to hit the endpoint in this way? My RestService implementation is as follows:
If this is not possible, would it be possible to focus on the Intellij application from within the RestService implementation? So when we call the endpoint at /api/intellij/pkce/redirect we can focus the correct Intellij window to the user (emulating the redirect behavior I'm trying to achieve using idea:// syntax?
Appreciate your help,
David
I found a way to get this to work using Jetbrains Toolbox and by providing an implementation of JBProtocolCommand and registering it in plugin.xml. Using toolbox, I can call my protocol handler using the following and retrieve the query parameters from the browser redirect:
However this is a little clunky because as an Enterprise, we have tight control over what versions of Jetbrains are installed and available to us. Therefore the functionality provided by toolbox are mostly not required, and it would be preferred that we didn't have to install it to use the protocol handler.
Can a protocol handler implementation be registered and invoked without flowing through Toolbox? I would need control over what version of Intellij is opened (Intellij Ultimate vs Intellij CE) as different developers use different versions of Intellij in my company, so ideally there would be different protocol handlers within the same plugin that could handle requests depending on which version of Intellij they have installed.
Thanks, David
Hi, sorry for delay. There is some information here, does it help https://youtrack.jetbrains.com/issue/IJSDK-602?
Yann Cebron - currently I have been able to use the protocol handler as detailed in your link successfully (see previous posts above).
My problem is that it mandates that Toolbox is installed, but I was looking for another approach that would achieve the same thing but without the need for Toolbox.
I explored a few options as detailed in this thread (e.g. using a RestService but had issues using the idea:// protocol), but I didn't have any success beyond using Toolbox and a custom protocol handler.
If you would have any suggestions I would appreciate them.
Thanks, David
Hi, wanted to bump this post again to gain insight on any other options that might be available.
Thanks,
David
Hello David, I would recommend you to use the local web servers and a `http://localhost:<port>` redirect approach in your setup. You are right that `jetbrains://` protocol is handled by the toolbox. Moreover, it's quite tricky to get the right IDE instance activated from the. Right now we do not have any specific URL handler inside the IntelliJ Platform on which you could count on.
Please note, that the IntelliJ HTTP server port is not always fixed. IDE may use neighboring ports if some ports are busy. You may get the port from the API by calling
I would recommend using a more specific URL on the callback that has your plugin name or something in the URL to avoid clashing with other plugins. (The one in the code above is not the best "intellij/pkce/redirect" and may clash)
You'd still need to implement the PCKE processing in the IDE plugin.