microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.07k stars 28.51k forks source link

Support automatically signing in via authentication providers #120439

Open heaths opened 3 years ago

heaths commented 3 years ago

Profile synchronization is nice, and being able to automate installation of extensions is great for setting up new machines, but keeping a separate list is onerous. Instead, it would be great if signing in could be automated.

For example, could the GitHub authentication provider be changed to support authenticating against stored credentials from the gh CLI? We do something similar like this with Azure SDK's DefaultAzureCredential, which a couple of the chained credential providers attempt to securely extract authentication tokens from the Azure (az) CLI or Azure (Az) PowerShell module. The gh CLI already provides a way to automate authentication, or at the very least offloads the responsibility of logging in via Code, mitigating a whole new workflow for non-visual authentication (which doesn't seem to be supported currently).

So a machine prep script could:

  1. Install gh CLI and Code (using winget, for example):
    winget install GitHub.cli
    winget install vscode-user-x64
  2. Authenticate to GitHub:
    gh auth login --with-token < mytoken.txt
  3. Force a sync:
    code --sync-profile # or something like that
heaths commented 3 years ago

Digging in a bit more, having some way to force authentication via providers could, for example, make a similar call as to GitHubAuthenticationProvider.manuallyProvideToken but accept input as opposed to prompting or, better, told to go discover alternative methods like using gh CLI's token or, for Microsoft auth, using its credential flow even if that means prompting to authorize. If authentication providers each had such a method, this could be abstracted away to a command line switch like:

code --authenticate ${token}@github --sync on # or maybe separate commands if ordering/timing is a concern
heaths commented 3 years ago

Adding @schaabs who is the architect for Azure SDK's DefaultAzureCredential since I'm probably over-simplifying the solution. I'm wondering, too, if MSAL for JS can help with automated workflows for AAD/MSA, and if a refresh token might be necessary to store in gh CLI's hosts.yml instead of just reusing the OAuth token. We should probably consult with our colleageus in GitHub in any case.