-
Notifications
You must be signed in to change notification settings - Fork 335
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 👍
There was a problem hiding this 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) || |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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:
- The browser send the instance url to the IDE
- 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()) |
There was a problem hiding this comment.
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:
- The browser send the instance url to the IDE
- 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
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
Note: For initial version I limited just to workspace domains. But we can generalize that to allow other instance domains.
Test plan