Repository navigation
Description
Goal
To streamline authentication for users connecting to GitHub or GitHub Enterprise for the purposes of using a GitHub application. Ideally, the user doesn't have to anything beyond logging into their account and authorizing access to an application (without copy pasting tokens).
Authentication tokens and scopes:
GitHub APIs almost always require a token to access them. Some don't (because the data is public for eg.), but anonymous calls are severely rate limited, so any app using the API for public data will need a token at some point
The API has a granular permission system, and a token will have scopes attached to it, so that only those endpoints or actions that the scopes allow will be usable.
- Git operations only need a
reposcope - GitHub API operations can need other scopes -
user,discussion,gist, etc, depending on what they're doing.
There are three ways to obtain a token:
-
The user creates a personal access token in their settings page and select the scopes.
- Pros: The application doesn't need to be registered anywhere or handle authentication.
- Cons: This is error prone and requires a lot of manual steps for the user.
-
The application obtains a token on behalf of the user by doing the oauth2 web authentication flow - opening a browser to the server that will show the requested permissions for the user to authorize, and returning the token to the app
- Pros: The user can see what permissions the application is requesting. If the user has already given this application these permissions before, the step is automatic and the user doesn't have to do anything at all
- Cons: Requires the application to listen to a webrequest in some way, which can be problematic behind firewalls
-
The application obtains a token on behalf of the user by asking the user for their username and password, their 2FA code, and calling the GitHub OAuth rest API endpoint with this information, along with the desired scopes, and obtaining a token in return.
- Pros: No need for external browsers or listening to web requests, everything is handled by the application
- Cons: Doesn't work for SSO-enabled organizations
The oauth webflow for applications
While the OAUTH Rest API is usable by any desktop app, the webflow is more complicated. The web flow requires that GitHub redirect the user to a known URI at the end of the authentication - this request includes the token in the body. For desktop applications, this is a bit tricky to pull off.
There are strategies around this:
-
Desktop applications that have their own installers can install a protocol handler on the system, and configure the redirect URI to be a particular protocol (like desktop:// or something://).
- apps using this approach: Desktop
- Pros: doesn't require listening to any web requests
- Cons: Requires an installer with permissions to install the protocol handler. The handler can be overridden by any app at any time
-
The application can listen on a known port on localhost, and the callback URI is configured to http(s)://localhost:PORT.
- apps using this approach: GHfVS
- Pros: localhost listeners bypass the network stack entirely (implemented on the loopback interface), so no data goes out to the network at all when the browser loads a
localhostaddress (i.e. no one can sniff the data). That means we can use http, and listening on ports above a certain range does not require admin permissions - Cons: Since the callback URI is fixed in the oauth app on GitHub, there is no way to do dynamic ports on the listener. That means that if something else on the system is using that particular port, we can't do the webflow at all.
-
The callback URI is configured to go to a separate webservice/webapp (running on heroku for eg.). The local application opens a websocket to the webservice to prepare it for handling the authentication, and the webservice handles all the redirects for the webflow. Once the webservice receives the token, it sends it back to the local application via the websocket
- apps using this approach: Git Kraken
- Pros: no local port conflicts, no local webservers listening on things. The application doesn't need to store the clientId and clientSecret data, that's on the webservice (which is a big plus)
- Cons: Would this work behind a heavily proxies firewall? Unsure
What the extension does today
Right now, the extension requires the user to create a token manually and store it in the settings file. If there isn't a token in the settings, it will try to use whatever is available to Git via the credential helper - which is brittle, given that that token might not have enough permissions.
/cc Rachel Macfarlane (@RMacfarlane) Sarah Guthals (@sguthals) David Wilson (@daviwil)
Activity
shana commentedon Jul 13, 2018
Oof, ok, that was a bit of a brain dump. I have a local patch to add support for the webflow with the localhost approach, as a rough draft to see how that would work. I'll push that for discussion soon (probably monday 'cause haha it's late here).
auchenberg commentedon Jul 24, 2018
Andreia Gaita (@shana) We support custom protocol handlers for VS Code extensions, so you could register a custom handler in the extension for the authentication url callback. See https://code.visualstudio.com/updates/v1_23#_protocol-handler-api. To me 1) sounds like the easiest scenario to get going.
shana commentedon Jul 24, 2018
Kenneth Auchenberg (@auchenberg) Oh that's handy, I'll look into it, thanks!
auchenberg commentedon Aug 21, 2018
Closing this issue, as we have landed the first version auth. We'll resume the conversation if auth needs tweaks.
devinrhode2 commentedon Mar 24, 2023
ProTip: If you have multiple github.com accounts, you can use this little button in the bottom left to control which accounts/extensions are connected:

andrewpomeroy commentedon Aug 9, 2023
Under what key? Or is this not even an option anymore?
brettforbes commentedon Apr 30, 2024
ITs a complete disgrace that setting the personal token is so hard to work out!!!! Why dont you have this in the documentation?????????
Pycharm makes it easy, so it is very hard to swap to VS Code, when you make it so hard!!! Why??????
Your docs point to this page, which does not even describe what to do. Why???????????
https://code.visualstudio.com/docs/sourcecontrol/github
devinrhode2 commentedon May 21, 2024
brettforbes commentedon May 21, 2024
Devin Rhode (@devinrhode2)
The reason may not be obvious, but i am primarily an engineering scientist, not a computer scientist. I program as a means of enabling my more interesting enquiries to be more insightful. As such, I really can't be bothered learning all of the Github commands, that to you seem so trivial, since i have more interesting problems in mind, and limited time.
I am currently using PyCharn, which makes it easy to copy and paste in my PAT, every time. It will prompt me if my github token has expired, and generally makes it trivial to contribute key pieces, and have the comp sci people sort it out. I am sure you are a complete guru on the comp sci, so it must be perplexing as to why I got frustrated.
I seriously do not want to spend the time working out how to go to another environment, and remember yet another syntax. Like why should I?
I like VS Code, it is well-written software, but i don't switch to it mostly because of this small thing, strange as it may seem. My comment was injected when i was trying to use it on a tight deadline, and I wasted some time trying to sort it out, so I had to renew a year's subscription of PyCharm. Mind you it is better at handling large JSON's and it is visually more appealing
pompa38musti-pixel commentedon Jun 11, 2026