Remkop
Remkop

Reputation: 133

How to use PAT on Azure DevOPS Server to clone a git repo

Hi we are trying to clone a git repo from our local Azure DevOps server 2020.0.1. We are using the command bellow, but it is not working. Should this be possible?
The documentation I try to follow is this. But it is a bit unclear.

git clone https://{an username:yourPAT}@yourURL/yourOrgName/yourProjectName/_git/yourRepoName

We then get an error: "fatal: Authentication failed for "
We also tried variations like 'yourname:yourPAT', 'yourPAT', ':yourPAT', 'yourPAT:' We want to use PAT's together with SmartGit

We then tried to use the other method mentioned (but when reading this is only needed when using basic authentication, we never enabled this on our ADOS-server, and is also not an authentication method on our IIS-website:

$MyPat = 'yourPAT'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
git -c http.extraHeader="Authorization: Basic $B64Pat" clone https://{yourURL/yourOrgName/yourProjectName/_git/yourRepoName

This one is working

The PAT we created is with full scope and access to all organizations.
The PAT is working to add an Agent.
We can also use it to access the RESTAPI (with curl you should -u and random or empty username, so bla;yourPAT).

Any advice is appreciated.

Upvotes: 5

Views: 3092

Answers (1)

Kevin Lu-MSFT
Kevin Lu-MSFT

Reputation: 35464

Based on your description, when you use the basic auth to run the git command, it could work.

It seems that the basic auth is enabled.

If you enable IIS Basic Authentication for Azure Devops server, PATs aren't valid. See Enabling IIS Basic Authentication invalidates using Personal Access Tokens.

If you use Git with IIS Basic Authentication, Git breaks because it requires PATs for user authentication. Although we don't recommend you use IIS Basic Authentication, by adding an extra header to Git requests, you can use Git with IIS Basic Authentication:

You could open IIS Manager -> IIS -> Authentication and check if the Basic Authentication is disabled.

enter image description here

On the other hand, you could remove the Azure DevOps Server related credentials from Credential Manager: Open the control panel on windows–> Click on User Accounts–> Click on Manage your Credentials–>Click on Windows Credentials, locate the entry for your remote git repository–>Click on the item in the list and select Remove–> Finally try to use PAT again to clone a git Repo.

Upvotes: 1

Related Questions