[英]Azure Devops OnPremise, fatal: Authentication failed for when cloning Git repo
Using OnPremise Azure Devops 2019 server I am trying to programmatically clone a git repository by calling the following git command inside a ProcessInfo:使用 OnPremise Azure Devops 2019 服务器我正在尝试通过在 ProcessInfo 中调用以下 git 命令以编程方式克隆 git 存储库:
clone https://{username}:{PATTOKEN}@{DEVOPSSERVERDOMAIN}/{TEAMPROJECT}/_git/{PROJECT}
Here is the c# code:这是 c# 代码:
var gitInfo = new ProcessStartInfo
{
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
FileName = pathToGitExe
};
Process gitProcess = new Process();
gitInfo.Arguments = theCloneCommand
gitInfo.WorkingDirectory = workingFolder;
gitProcess.StartInfo = gitInfo;
gitProcess.Start();
But I keep getting the error但我不断收到错误
Cloning into 'PROJECT'...
fatal: Authentication failed for '{DEVOPSSERVERDOMAIN}/{TEAMPROJECT}/_git/{PROJECT}'
Is the PAT not correctly used?是否未正确使用 PAT? Any suggestions
有什么建议么
As far as I can see, you should try the clone without username
.据我所知,您应该尝试不带
username
的克隆。
https://github.com/MicrosoftDocs/azure-devops-docs/issues/2455 https://github.com/MicrosoftDocs/azure-devops-docs/issues/2455
https://<PAT>@mydomain.visualstudio.com/myproject/_git/myrepo
If you enable IIS Basic Authentication for Azure Devops server, PATs aren't valid.如果为 Azure Devops 服务器启用 IIS 基本身份验证,则 PAT 无效。 See Enabling IIS Basic Authentication invalidates using Personal Access Tokens .
请参阅使用个人访问令牌启用 IIS 基本身份验证无效。
As it is said in above document, you need to add an extra header which includes a base 64 encoding of "user:PAT" to the Git requests:正如上面文档中所说,您需要向 Git 请求添加一个额外的 header,其中包括“user:PAT”的 base 64 编码:
git -c http.extraheader='Authorization: Basic [base 64 encoding of "user:PAT"]' ls-remote http://tfsserver:8080/tfs/DefaultCollection/_git/projectName
You can Base64-encode the username and PAT using below poweshell script:您可以使用以下 poweshell 脚本对用户名和 PAT 进行 Base64 编码:
$MyPat = 'yourPAT'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("user:$MyPat"))
Or with C# code:或使用 C# 代码:
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "user", personalaccesstoken))));
For more information, See document here .有关详细信息,请参阅此处的文档。
You can try using your userName and password instead of PAT as authentication:您可以尝试使用您的用户名和密码而不是 PAT 作为身份验证:
git clone https://{username}:{password}@{DEVOPSSERVERDOMAIN}/{TEAMPROJECT}/_git/{PROJECT}
#if your password or username contain @ replace it with %40
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.