无法使用 PAT 从 Azure DevOps 克隆 git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53106546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:13:56  来源:igfitidea点击:

Cannot clone git from Azure DevOps using PAT

gitauthenticationazure-devopstokenaccess-token

提问by Jose

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

我无法从 Azure DevOps 克隆一个简单的存储库。操作系统: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)
  • 进入 Azure DevOps
  • 点击右上角我的用户名
  • 转到安全选项卡
  • 创建一个包含所有范围的 PAT(确保没有范围问题)
  • 将 PAT 复制到剪贴板
  • 将 PAT 粘贴到其他地方以确认 PAT 已被正确复制(我知道......不安全,但这超出了本问题的范围)
  • 转到我的控制台
  • 问题: git clone https://myorganization.visualstudio.com/myproject/_git/myrepo/
  • 我输入用户名和密码(PAT)

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

我不断从 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.
  • https://usename:[email protected]/myproject/_git/myrepo/的形式传递令牌,我真的很惊讶人们说这有效......因为我的 git 抱怨,因为相信 : 意味着端口。
  • 尝试激活/停用 git 的凭证管理器 * 在 Windows 和 Ubuntu 上尝试过。
  • 尝试激活和停用简单凭据。
  • 尝试使用简单的凭据,即用户名 + 密码。
  • 试图将我的用户名放在https://username@....
  • 尝试使用 SSH
  • 尝试在 git 命令中使用 http.extraHeader ,标题为
    Authorization: Basic Base64Encoded(uname:PAT)
  • 尝试在 git 命令中使用 http.extraHeader ,标题为
    Authorization: Bearer PAT
  • 尝试使用 VSCode 客户端。它自己生成 PAT,但仍然无法进行身份验证和克隆。
  • 尝试使用 Rider VSTS 客户端。它自己生成了 PAT,但仍然无法进行身份验证和克隆。
  • 尝试使用适用于 Linux 的 git 凭证管理器。它提示代码,当我们在浏览器中进行身份验证时,它会成功生成 PAT。尽管如此,之后无法进行身份验证。

Any clue why this is not working?

任何线索为什么这不起作用?

回答by JSM

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

我遇到了同样的问题,并花了很长时间寻找解决方案。我终于在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.

简而言之,需要通过 git http.extraheaders 传递用户名和编码为 base64 的 PAT 以进行身份​​验证。

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

100% 感谢原作者,仅将其包含在此处以帮助其他人找到它:

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

示例: git -c http.extraheader="AUTHORIZATION: Basic TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRhs /projectfCollection/projectfCollectoName/address/gitreppo

使用的基本令牌 BASE64 编码:TXlHaXRTeW5jVXNlcjo2bHFqNXJkcHEzdXBxZWVmd2o3bDduZXN5NTR3d3gxNHFobDVlanl5NTVkb2g0M3d4YzRh

基本令牌 BASE64 解码:MyGitSyncUser:6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

令牌构造自:在此示例中:虚构用户名:MyGitSyncUser 使用的 PAT:6lqj5rdpq3upqeefwj7l7nesy54wwx14qhl5ejyy55doh43wxc4a

I hope this helps!

我希望这有帮助!

回答by jabu.hlong

I have had success using PAT like this;

我像这样使用 PAT 取得了成功;

  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;
  1. 复制您的存储库的克隆 URL,例如 git clone https://<domain>.visualstudio.com/<domain>/_git/<domain>
  2. 复制后,将 PAT 用作;

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

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

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

不需要用户名或密码,因为 PAT 就足够了。

回答by Congyi Wu

This is a known regression in curl 7.61.0, which ships with Ubuntu 18.10. The regression was fixed in curl 7.61.1, but Ubuntu 18.10 doesn't have this fix yet. See (and upvote) https://bugs.launchpad.net/ubuntu/+source/curl/+bug/1805203

这是 curl 7.61.0 中的一个已知回归,它随 Ubuntu 18.10 一起提供。回归在 curl 7.61.1 中得到修复,但 Ubuntu 18.10 还没有这个修复。请参阅(并投票)https://bugs.launchpad.net/ubuntu/+source/curl/+bug/1805203

回答by AzuxirenLeadGuy

I was having the same problem and got it solved using HTTPS only.

我遇到了同样的问题,仅使用 HTTPS 就解决了。

I figured out that I had to use the terminal only rather than using any "GUI shortcuts" dev.azure provides since they are meant for a git-credential-manager which works fine on windows but is broken for Ubuntu.

我发现我只需要使用终端而不是使用 dev.azure 提供的任何“GUI 快捷方式”,因为它们适用于 git-credential-manager,它在 Windows 上运行良好,但在 Ubuntu 上已损坏。

Apparently, the dev.azure git repository has a different credentials (which you need to set up) rather than your Microsoft account credential.

显然,dev.azure git 存储库具有不同的凭据(您需要设置)而不是您的 Microsoft 帐户凭据。

Let's say my Microsoft account username is [email protected], with its password Jd1986

假设我的 Microsoft 帐户用户名是 [email protected],密码是 Jd1986

This credential will NOTwork if you try for git cloning, as you needto generate git credential for your project and then use it.

该证书将工作,如果你尝试git的克隆,因为你需要生成凭证的git为您的项目,然后使用它。

You can generate git credential from here, enter image description here

您可以从这里生成 git 凭证, 在此处输入图片说明

After this, Save it and use the set credential. enter image description here

在此之后,保存它并使用设置的凭据。 在此处输入图片说明

Go to your terminal, and use the HTTP url for git clone and enter the given credential. This worked for me.

转到您的终端,并使用 git clone 的 HTTP url 并输入给定的凭据。这对我有用。

回答by Salman

Try : First delete the git credentials from Credential manager. Try Generating a new personal access token to resolve this error

尝试:首先从凭证管理器中删除 git 凭证。尝试生成新的个人访问令牌以解决此错误

Error

错误

Go to security ->Personal access token->Add Give Description, select All scopes, click Create Token.

进入安全->个人访问令牌->添加描述,选择所有范围,点击创建令牌。

PAT

拍

Copy the token and store it for later use. This token can now be used in place of password for the git user.

复制令牌并存储以备后用。现在可以使用此令牌代替 git 用户的密码。

Token

令牌