Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot clone git from Azure DevOps using PAT

I cannot clone a simple repository from Azure DevOps. OS: Ubuntu 18.10

I do this:

  • Got to Azure DevOps
  • Click on the top right corner on my user name
  • Go to the security tab
  • Create a PAT with all the scope (to be sure there is no scope problem)
  • Copy the PAT to the clipboard
  • Paste the PAT somewhere else to confirm the PAT has been copied correctly (I know... not safe but that is out of the scope of this question)
  • Go to my console
  • Issue: git clone https://myorganization.visualstudio.com/myproject/_git/myrepo/
  • I enter the user name and the password (the PAT)

I keep getting this message from Git: fatal: Authentication failed for 'https://myorganization.visualstudio.com/myproject/_git/myrepo/'

I was reading the solutions of other people but none worked for me. I also tried this:

  • Pass the token in the form https://usename:[email protected]/myproject/_git/myrepo/ I am really surprised people say this worked... for my git complains because believes the : means the port.
  • Tried to activate/deactivate credential manager of git * Tried on Windows and Ubuntu.
  • Tried to activate and deactivate the simple credentials.
  • Tried with the simple credentials, i.e. username + password.
  • Tried to put my user name in https://username@....
  • Tried to use SSH
  • Tried to use the http.extraHeader in the git command with the header being
    Authorization: Basic Base64Encoded(uname:PAT)
  • Tried to use the http.extraHeader in the git command with the header being
    Authorization: Bearer PAT
  • Tried to use the VSCode client. It generates the PAT by itself but still cannot authenticate and clone.
  • Tried to use the Rider VSTS client. It generates the PAT by itself but still cannot authenticate and clone.
  • Tried to use the git credentials manager for Linux. It promps the Code and when we authenticate in the browser, it generates a PAT successfully. Still, after that cannot authenticate.

Any clue why this is not working?

like image 558
Jose Avatar asked Nov 01 '18 17:11

Jose


People also ask

How do I clone a repository from Azure DevOps to Visual Studio 2019?

Visual Studio 2019 version 16.8 and laterOn the start window, select Clone a repository. In the Browse a repository section, select Azure DevOps. If you see a sign-in window, sign in to your account. In the Connect to a Project dialog box, choose the repo that you want to connect to, and then select Clone.

Can you use Git with Azure DevOps?

After you create a new organization and project in Azure DevOps, you can begin coding with Git. To work with a Git repo, you clone it to your computer. Cloning a repo creates a complete local copy of the repo for you to work with.


3 Answers

I have had success using PAT like this;

  1. copy clone url for your repository e.g. git clone https://<domain>.visualstudio.com/<domain>/_git/<domain>
  2. After you have copied you PAT use as;

git clone https://<PAT>@<domain>.visualstudio.com/<domain>/_git/<domain>

No Username nor password should be required as the PAT should suffice.

like image 197
jabu.hlong Avatar answered Oct 22 '22 16:10

jabu.hlong


I've experienced the same issue, and spent quite a while searching for a solution. I finally came across this post which contained a solution in the comments section by Martinius79.

In short, it was required to pass the username and PAT, encoded as base64, through git http.extraheaders in order for it to authenticate.

100% Credit to the original author, just including it here to assist others in locating it:

Example: git -c http.extraheader="AUTHORIZATION: Basic TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh" clone https://tfs.address/tfs/Collection/Project/_git/RepoName

Used basic token BASE64 encoded: TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh

Basic Token BASE64 decoded: MyGitSyncUser:6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

Token is constructed from : In this example: Fictional user name: MyGitSyncUser Used PAT: 6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

I hope this helps!

like image 20
JSM Avatar answered Oct 22 '22 14:10

JSM


This official guide procedure worked for me, but with one important point. When base64-encoding, one must put attention to non-printable characters.

The guide says:

MY_PAT=yourPAT      # replace "yourPAT" with your actual PAT
B64_PAT=$(printf ":$MY_PAT" | base64)
git -c http.extraHeader="Authorization: Basic ${B64_PAT}" clone 
https://dev.azure.com/yourOrgName/yourProjectName/_git/yourRepoName

Using "echo" instead of "printf" would insert a newline char, changing the base64 string (probably would work also with "echo -n" but I haven't tried). Also, do not include the username, as per the snippet above.

Used git 2.17.1 on Ubuntu 18.04.

like image 5
El_Monto Avatar answered Oct 22 '22 16:10

El_Monto