4

Our organisation required us to add 2FA to github. Unfortunately, now we cant commit our work in visual studio code. VSCode prompts for username and password. It doesnt know about 2FA.

There are some very old posts saying to use a personal access token (PAT), e.g.

https://colinmackay.scot/2015/07/15/two-factor-authentication-with-github-and-visual-studio-2013/comment-page-1/#comment-29984

http://www.anilsezer.com/connecting-github-from-visual-studio-after-twofactor-authentication-enabled

However, this does not work either.

The first article says enter the PAT as the username and leave the password blank in the VSCode github login dialog. This does not work as you cant sumbmit with a blank password. Entering a random password gives

Fatal: HttpRequestException encountered.
   An error occurred while sending the request.
fatal: HttpRequestException encountered.
   An error occurred while sending the request.
remote: Invalid username or password.
    fatal: Authentication failed for 'https://github.com/xxx/xxx.git/'

The second article says to use your user/email as the username, and enter the PAT as the password. This is also what the VSCode documentation says. Tired this too, same problem.

Anyone got this working?

Also, does anyone know which of the "scopes" is required for VSCode? I just ticked "repo". Could this be the problem, are more required?

John Little
  • 10,707
  • 19
  • 86
  • 158
  • Can you commit from terminal – Ahmet Zeybek Apr 13 '18 at 05:29
  • 1
    Just tried it, using a Personal Access Token allowed me to push and pull from VSCode – Adam Jun 07 '18 at 08:52
  • 1
    I was also able to use my username and the PAT as password when doing a push to my repo. Can't figure out how to get that to save though (VS Code asks me for credentials every time) – Craig Eddy Jul 03 '18 at 16:47
  • July 2019 and this issue still exists, For me the issue was that I have enabled two-factor Auth and when I try to connect to Github via VS code terminal I am asked for credentials, after entering my user name and password I get a screen to enter my OTP sent to mobile, But I am not receiving any OTP (but it works outside VS code, I do receive a OTP) so I am not able to move forward from here. Luckily the same solution as discussed here about using the `Personal Access Token` instead of the password in the credentials prompt skipped the two-factor authentication and connected successfully. – Rajshekar Reddy Jul 27 '19 at 14:04

1 Answers1

6

I would advise you can use Personal access tokens. Just click on your profile picture on the site https://github.com/ (after login), then on Settings > Personal access tokens > Generate new token. Follow the wizard to select what to grant, at least you'll need repo.

On VS Code you provide your usual user name and for password you provide the newly generated PAT.