question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Too many redirects or authentication replays' on clone from TFS

See original GitHub issue

After updating to Team Foundation Server TFS 2018 & 2017 Update 3, we are not be able to login to GIT repository using LibGit2Sharp library using Access Token. Please check the code below:

    `
    string accessToken = "eyJ0eXAiOiJKV1QiLCJ...";
    NetworkCredential gitCredentials = new NetworkCredential(string.Empty, accessToken);
    string localRepoPath = string.Empty;
    string gitTfsRepo = "http://mjtfs2017:8080/tfs/DefaultCollection/_git/GITTest001";

    try
    {
        localRepoPath = Repository.Clone(gitTfsRepo, @"D:\temp\GIT",
            new CloneOptions()
            {
                CredentialsProvider = GetCredentialsHandler(gitCredentials),
                IsBare = false
            });

    }
    catch (Exception err)
    {
        Console.WriteLine(err);
    }

    Console.WriteLine(localRepoPath);
    `

I communicated with Microsoft TFS/VSTS Team they gave following response:

The fact that you received those responses from the code snip I provided means that your extension is correctly configured (regarding scopes at least) and TFS is correctly accepting the extension’s access token to perform git operations through HTTP, when the git client sends it.

Additionally, if I use the next command, using git for Windows, I’m able to fully interact with a TFS repo with that access token:

git -c http.extraheader=“Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJ…” clone http://at1-tfs-test1-angallo.westus2.cloudapp.azure.com:8080/tfs/DefaultCollection/_git/test_project_1

But that same command doesn’t work for git for Linux, probably because my git client on my Linux machine doesn’t send or correctly consider these HTTP headers (just as LibGit2Sharp seems to not do too (from your latest Fiddler trace I still see the Authentication header missing)). So I still believe the problem here comes from the git client, not TFS or the access token.

Please suggest, thanks in advance.

LibGit2Sharp version: 0.26.0-preview-0027

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mayrbenjamin92commented, Jan 18, 2022

Hi guys! This response might be surprising, but: We could actually fix this! In my case, our PAT (=Personal access token) was expired! I just had to create a new token and cloning worked, again! Wanted to share this as I was also searching for solutions for quite some time! The error message is just a bit misleading…

@Sherry112, @PatrickGrub 😃

3reactions
sfwestercommented, Nov 23, 2021

Ran into similar issues when trying to clone from an on premise Azure Devops Server 2020 into a docker container.

We were able to get it working by doing the following while having Basic Authentication disabled.

var token = "myPatToken";
var byteArray = Encoding.ASCII.GetBytes(":" + myPatToken);
var encodedToken = Convert.ToBase64String(byteArray);

var options = new CloneOptions
{
    FetchOptions = new FetchOptions
    {
        CustomHeaders = new[]
        {
            $"Authorization: Basic {encodedToken}"
        }
    }
};

return Repository.Clone("https://...", ".", options);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Git sync failing - too many redirects or authentication replays
Hi All, When we browse to the Plans or Assets pages, we receive the following error: (500) Server Error too many redirects or...
Read more >
LibGit2Sharp: Fetching fails with "Too many redirects or ...
I tried @Carlos' suggestion in the following way: public static void GitFetch() { var creds = new UsernamePasswordCredentials() {Username ...
Read more >
GitLib2Sharp Repository.Clone error "Too many redirects or ...
I'm having problems with cloning a repository from my TFS-server which I run locally. This server is authenticated with NTLM. This is my...
Read more >
Open Git Project - Progress Test Studio - Documentation
If you are not able to connect to the Git system and get a message Error connecting to Git, too many redirects or...
Read more >
[Otter] Unable to connect to TFS Git with authentication
I'm trying to create Raft using TFS git and I'm getting following error [LibGit2SharpException: Too many redirects or authentication replays] LibGit2Sharp.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found