Add new token creation callback page to improve current auth flow for integration purpose
Created by: abeatrix
Closes https://github.com/sourcegraph/sourcegraph/issues/28311
Summary
This PR adds a new token creation callback page to improve the current auth flow for integration purposes, eg. VS Code Extension and JetBrain Extension.
Current Problem
Users rely on our access token to make API requests to Sourcegraph, and a lot of our extensions and features depend on it; however, The current auth flow to retrieve an access token is not seamless. See steps outlined in our docs.
Take VS Code for example:
- Visit the VS Code extension homepage
- Users are prompted to sign in / sign-up for a Sourcegraph account
- Perform sign-in / sign-up in browser
- Navigate to the User setting page
- Move to Access Token page
- Click Generate new token
- Fill in the description
- Click Generate token
- Copy the new token
- Move back to VS Code
- Paste the new token
Proposed Solution
A new token creation page that performs callbacks ( https://sourcegraph.com/user/settings/tokens/new/callback
) that can be shared with different integrations as long as the URL params that are being passed in via the URL (https://sourcegraph.com/user/settings/tokens/new/callback?requestFrom=$SOURCE
) is included in our predefined list. Once the source has been validated, it would redirect the user back to the source using the predefined redirect URL with the newly created token passing in as a new URL param, which then can be processed by the extension's URL handler (For the sourcegraph vs code extension, the link is vscode://sourcegraph/sourcegraph?code=$TOKEN
)
See Loom Video here: https://www.loom.com/share/8a668f4624e349ce9358325f000fe9e5
The proposed auth flow for VS Code as an example:
- Users are prompted to sign-in / sign-up for a Sourcegraph account
- Perform sign-in / sign-up in browser
- The user will be redirected to the token creation callback page
- It reads the url params and checks if the params are valid (if it is on the allow list)
- If the param is valid, it will generate the token automatically
- User will be redirected back to the extension and the token will be imported via the built-in URL handler by the extension
Screenshots
VS Code Extension (VSCE)
-
Token will be created automatically and asked if they want to redirect back to the app
-
Token imported to app automatically without copying and pasting manually
SRC CLI
Test plan
Consulting with the Security Team (slack thread)
To test this PR:
- Set up a test instance using
sg start
- In your VS Code User setting, set the URL to your test instance's URL:
"sourcegraph.url": "https://sourcegraph.test:3443/"
- Change the name in the
client/vscode/package.json
from@sourcegraph/vscode
tosourcegraph
- Follow this guide to build and run the extension
App preview:
Check out the client app preview documentation to learn more.