[英]Azure Devops OnPremise, fatal: Authentication failed for when cloning Git repo
使用 OnPremise Azure Devops 2019 服务器我正在尝试通过在 ProcessInfo 中调用以下 git 命令以编程方式克隆 git 存储库:
clone https://{username}:{PATTOKEN}@{DEVOPSSERVERDOMAIN}/{TEAMPROJECT}/_git/{PROJECT}
这是 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();
但我不断收到错误
Cloning into 'PROJECT'...
fatal: Authentication failed for '{DEVOPSSERVERDOMAIN}/{TEAMPROJECT}/_git/{PROJECT}'
是否未正确使用 PAT? 有什么建议么
据我所知,您应该尝试不带username
的克隆。
https://github.com/MicrosoftDocs/azure-devops-docs/issues/2455
https://<PAT>@mydomain.visualstudio.com/myproject/_git/myrepo
如果为 Azure Devops 服务器启用 IIS 基本身份验证,则 PAT 无效。 请参阅使用个人访问令牌启用 IIS 基本身份验证无效。
正如上面文档中所说,您需要向 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
您可以使用以下 poweshell 脚本对用户名和 PAT 进行 Base64 编码:
$MyPat = 'yourPAT'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("user:$MyPat"))
或使用 C# 代码:
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "user", personalaccesstoken))));
有关详细信息,请参阅此处的文档。
您可以尝试使用您的用户名和密码而不是 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.