【问题标题】:How do you authenticate to VSTS using LibGit2Sharp?如何使用 LibGit2Sharp 对 VSTS 进行身份验证?
【发布时间】:2016-04-29 00:06:49
【问题描述】:

我正在尝试使用 LibGit2Sharp 克隆 VSTS(Visual Studio Team Services)存储库。我正在设置一个 CredentialsHandlerUsernamePasswordCredentials 代表我的 Microsoft 帐户的凭据,我得到的结果是这样的:

LibGit2Sharp.LibGit2SharpException was unhandled
  HResult=-2146233088
  Message=Too many redirects or authentication replays
  Source=LibGit2Sharp

如果我什至无法输入我的实际用户名和密码,我不确定什么可行。

我也尝试使用DefaultCredentials 提到的here,但这似乎只适用于 TFS,而不是 VSTS(TFS 的 NTLM 凭据)。

【问题讨论】:

    标签: git tfs azure-devops libgit2sharp


    【解决方案1】:

    首先,您需要为您的帐户启用备用身份验证。请按照以下步骤执行此操作:

    1. 登录 VSTS 门户网站。
    2. 点击您的帐户名称,然后从右上角选择“我的个人资料”。
    3. 切换到“安全”面板。
    4. 选择“备用身份验证凭据”并进行配置。

    然后您可以使用替代凭据向 VSTS 进行身份验证。以下代码展示了如何向 VSTS 进行身份验证并执行克隆作业。

    using LibGit2Sharp;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string surl = "https://youraccount.visualstudio.com/DefaultCollection/_git/Remoterepo";
                string lpath = "C:\\LocalPath";
                CloneOptions co = new CloneOptions();
                string un = "alternativeusername";
                string pwd = "alternativepassword";
                Credentials ca = new UsernamePasswordCredentials() {Username = un, Password = pwd };
                co.CredentialsProvider = (_url, _user, _cred) => ca ;
                Repository.Clone(surl,lpath,co);
            }
        }
    }
    

    【讨论】:

    • 太棒了。实际上,我已经进入了那个区域并做对了所有事情,只是我认为我仍然可以使用我的主电子邮件地址和密码,现在只选中了复选框。看来您确实必须输入辅助用户名才能完成这项工作。您是否知道适用于 Windows 的 Git 凭据管理器 (github.com/Microsoft/Git-Credential-Manager-for-Windows) 是否允许使用常规凭据?
    猜你喜欢
    • 2017-12-23
    • 1970-01-01
    • 2017-12-19
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2017-11-24
    • 1970-01-01
    • 2017-03-11
    相关资源
    最近更新 更多