简体   繁体   English

Azure Devops OnPremise,致命:克隆 Git 存储库时身份验证失败

[英]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.

相关问题 验证到 Azure Devops Git repo - Authenticating to Azure Devops Git repo 如何使用 .NET 数据工厂 ZF20E3C5E54C0893D36 启用 DeVOPS GIT 存储库在 Azure 数据工厂中发布管道? - How to publish pipeline in Azure Data Factory enabled with DeVOPS GIT repo using .NET Data Factory SDK (C# )? LibGit2Sharp:如何使用自定义 HTTP 身份验证 header 中的个人访问令牌将本地回购提交提交到 Azure DevOps 远程回购? - LibGit2Sharp: How to push a local repo commit to Azure DevOps remote repo using a Personal Access Token inside a custom HTTP authentication header? Azure Devops REST API 与 ZD7EFA19FBE7D3972FD5ADB6024223D7 - Azure Devops REST API with C# Authentication Azure Devops Git - 按日期获取版本 - Azure Devops Git - Get version by date TFS为构建克隆git repos时出现AppDomainUnloadedException - AppDomainUnloadedException when TFS is cloning git repos for a build Microsoft Azure DevOps Repo:在特定分支中搜索文本/代码 - Microsoft Azure DevOps Repo: search for text/code in specific branch 无法从 C# 连接到 Azure DevOps Repo - Unable to connect to Azure DevOps Repo from C# c# azure devops repo builder 突然停止工作 - c# azure devops repo builder has stopped working suddenly Azure 错误:DefaultAzureCredential 身份验证失败 - Azure error: DefaultAzureCredential authentication failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM