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

feat(auth): Allow workspace to pre-populate URL for quick sign-in #6653

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mmanela
Copy link

@mmanela mmanela commented Jan 15, 2025

VS Code side part of https://linear.app/sourcegraph/issue/SRC-908/automate-cody-authflow-vs-code

After a user creates a workspace we want to make it easy for them to sign-in to the instance in their editor. For enterprise instances today, they need to copy the instance url, go into VS Code and then choose to signin with enterprise instance and then paste the url.

This change will help stream-line that flow by allowing the UI in sourcegraph to link to VS Code with a url like

vscode://sourcegraph.cody-ai?instance=someinstance.sourcegraphdev.app

VS Code will handle and either switch to that account if you already are auth'd OR pop-open the signin menu directly
image

Note: For initial version I limited just to workspace domains. But we can generalize that to allow other instance domains.

Test plan

  1. Validate when client doesn't have instance already
  2. Validate when client already has instance connected

@mmanela mmanela requested review from eseliger and abeatrix January 15, 2025 18:48
@@ -137,12 +160,12 @@ async function showAuthMenu(type: AuthMenuType): Promise<LoginMenuItem | null> {
/**
* Show a VS Code input box to ask the user to enter a Sourcegraph instance URL.
*/
async function showInstanceURLInputBox(title: string): Promise<string | undefined> {
Copy link
Author

Choose a reason for hiding this comment

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

This was odd? This is either never passed in OR is a url. Seems the right thing to do for a URL is populate the url and not make that a title.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a component originally created for the second step of their sign in flow where user is expected to enter their endpoint before we do the redirection. Since we have moved out away from using native vs code component, I think this should be fine to change.

@mmanela mmanela requested a review from evict January 15, 2025 18:51
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

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

👍 deferring approval to Bee who knows this codebase better in case there's any gotchas around the auth state stuff :)

const instanceUrl = instanceHost ? new URL(`https://${instanceHost}`) : undefined
if (instanceUrl && isWorkspaceInstance(instanceUrl.toString())) {
// Prompt the user to switch/setup with the new instance
await showEnterpriseInstanceUrlFlow(instanceUrl.toString())
Copy link
Member

Choose a reason for hiding this comment

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

So all this does is populate the URL and the user still has to confirm and proceed right? That feels low risk to me and like something that enterprise would benefit from as well - making it easier to onboard to cody feels useful. Maybe we can remove the workspaces special casing even when @evict agrees?

Copy link
Author

@mmanela mmanela Jan 15, 2025

Choose a reason for hiding this comment

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

Yea I put a screenshot in the description of what you see.

In terms of restrictions it depends on how general we want to be. If we want an onprem instance to work with this, then it needs to have 0 restrictions. But if we just targeted MT and Cloud we can add the cloud domain.

But I am not sure on risk of letting someone pre-fill customer domains.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good to me. I don't see issues with this approach. 👍

Copy link
Contributor

@abeatrix abeatrix left a comment

Choose a reason for hiding this comment

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

Left some comments inline. If we want to support other editors in the future, we will need to move away from using the input box into the webviews. Since this is expected to work with vs code only as discussed, the code change lgtm!

}
try {
return (
new URL(url).host.endsWith(Workspaces_Host_Prod) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: check for https protocol? Not sure if it'd help tho.

const instanceUrl = instanceHost ? new URL(`https://${instanceHost}`) : undefined
if (instanceUrl && isWorkspaceInstance(instanceUrl.toString())) {
// Prompt the user to switch/setup with the new instance
await showEnterpriseInstanceUrlFlow(instanceUrl.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

Just brainstorming for after the launch, what if we:

  1. The browser send the instance url to the IDE
  2. Here the handler received the instance URL, and then instead of showing the input box for the show enterprise instance url form, we just open the link to the account token page in browser where user needs to manually click on the approve button to send the token back to the client

const instanceUrl = instanceHost ? new URL(`https://${instanceHost}`) : undefined
if (instanceUrl && isWorkspaceInstance(instanceUrl.toString())) {
// Prompt the user to switch/setup with the new instance
await showEnterpriseInstanceUrlFlow(instanceUrl.toString())
Copy link
Contributor

Choose a reason for hiding this comment

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

Just brainstorming for after the launch, what if we:

  1. The browser send the instance url to the IDE
  2. Here the handler received the instance URL, and then instead of showing the input box for the show enterprise instance url form, we just open the link to the account token page in browser where user needs to manually click on the approve button to send the token back to the client

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.

4 participants