How to use visual studio code with github and 2FA - github

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?

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.

Related

Git Authentication failed. New generated token doesn't work

could someone help me to fix this issue?
I'm trying to connect my local repository to GitHub, but I have got this error.
I have tried so many times to solve it without success, following the documentation or generate a new token, as well.
Thanks in advance
Username for 'https://github.com': ...#gmail.com
Password for 'https://...#gmail.com#github.com':
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls
for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Username/horizontal-gallery.git/'
I would like to access again on my GitHub profile, and work with it.
Make sure the token you are entering as a password when prompted follows the new format:
ghp for GitHub personal access tokens
And make sure you are not creating a "fined-grained" PAT (Personal Access Token), as such token might be too limited in scope and would not work with a specific repository.
Try and create a classic PAT.

Personal Access Token not being accepted/recognised when cloning repo on Mac

Beginner developer here. I created a Personal Access Token (PAT) on Github so that I could clone a repo for local access. When terminal asks for credentials and I enter my PAT I get the error message below, which I interpret as terminal not recognising the token I entered as a PAT (ie terminal thinks I'm entering a standard password)
remote: Support for password authentication was removed on August 13,
2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/
for more information. fatal: Authentication failed for
'https://github.com/async-labs/builderbook.git./'
Answers to similar questions posted on Stack Overflow suggest updating keychain access with the PAT. This seems to be successful for many, judging by the upvotes and thankful comments. I've done this but am still getting the same error message.
I've verified the PAT that I'm copying into terminal is the same as the one served up by Github.
There was a suggestion that SAML SSO's may need to go through an additional process but that seems to be for enterprise account and mine is a personal account.
I'm using macOS Big Sur version 11.6
Urghhh. So, just reboot the computer (once you've updated your keychain) and it should work.

Github 2FA won't let me push to branch

Just added 2FA for Github but now when I go to push changes from the terminal to a branch and I try to authenticate myself with username + password I get rejected because there's nowhere to input my 2FA code...I know my username and password are correct because I can login to the site (with 2FA code). Terminal doesn't provide a space to input that code. How are others working around this?
You'll need a personal access token or SSH key.
The details are here: Accessing GitHub using two-factor authentication - Using two-factor authentication with the command line

How to solve an error while cloning a private repository

I have a repository which is private. Before, I was able to clone it from my terminal by giving the username and password. Few days back I got a mail from GitHub to enable 2FA in my account. I did but now I see my account password doesn't seem to work when I give my password in my terminal. I use Google Authenticator as my TOTP app and I also tried giving that password but still it says authentication failure. Please help me out
You need a "Personal Access Token" (PAT).
In order to generate one, go to your GitHub settings and click on the category called "Developer settings". In that section, go to personal tokens.
There you can generate a new access token (make surer to check repo). When you clone your repository, use this token instead of your password. Now you should be able to clone it.
You can read more about this process here: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token

How do I sign in to GitHub from command line after password access is removed?

GitHub is retiring password based authentication for command line tools: https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/
Normally I work in some server, git clone https://...., enter my username and password and get the code that I have to deploy.
What am I supposed to do now? Do I create a token, write it down on a piece of paper, take it with me and retype it into a terminal? Seems a bit too convoluted for just getting some code. Is there some other "intended" workflow?
There are a few options:
You can create a personal access token in your github settings and use that instead of your account password.
you can use SSH to connect
you can rely on the Git Credential Manager Core which will perform an OAuth check either by popping up a UI or giving you an url to paste into a browser.
some hardware tokens will enable you to perform authentication.