Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting exception "too many redirects or authentication replays" #2069

Open
AndersBillLinden opened this issue Dec 21, 2023 · 2 comments
Open

Comments

@AndersBillLinden
Copy link

AndersBillLinden commented Dec 21, 2023

I am trying to pull from a github repository with the following code getting an exception "too many redirects or authentication replays". Why? If I failed to login, I expect an exception telling me that. Also the exception suggests that it retried whatever it did a couple of times although "replay" needs clarification. Where do I configure the number of retries if any? I have no interest in trying more than once. I have checked the credentials many times and also I tried to pull from an azure devops repo with the same result.

public void dothepulling()
{
  string repoPath = "C:\\project\\test.git";

  using (var repo = new Repository(repoPath))
  {

    var FetchOptions = new FetchOptions
    {
      CredentialsProvider = func
    };

    var pullOptions = new PullOptions
    {
      MergeOptions = new MergeOptions
      {
        FastForwardStrategy = FastForwardStrategy.FastForwardOnly,
        FileConflictStrategy = CheckoutFileConflictStrategy.Theirs,
        IgnoreWhitespaceChange = false
      },
      FetchOptions = FetchOptions
    };

    var signature = new Signature(new Identity("Firstname Lastname", 
      "my.email.@address.com"), DateTimeOffset.Now);

    Commands.Pull(repo, signature, pullOptions);
  }
}

private UsernamePasswordCredentials func(string url, string user,
  SupportedCredentialTypes types)
{
  return new UsernamePasswordCredentials
  {
    Username = "username",
    Password = "password"
  };
}
@BrotherBrine
Copy link

I'm getting the same error as @AndersBillLinden on the Clone request. using LibGit2Sharp v0.28.0 and LibGit2Sharp.NativeBinaries v2.0.320

@old-guy-coder
Copy link

old-guy-coder commented Apr 17, 2024

I am seeing the same error on LibGit2Sharp v0.30.0, any update on this?

Update

I have the following code and have tried with CustomHeader and the UsernamePasswordCredentials set for the CredentialsProvider and get a 400 response back from Clone. The following code uses just the CustomHeader and gets the same 400 response.

sourceUrl is https://{orgName}@dev.azure.com/{orgName}/{projectName}/_git/{repoName}

var repoPath = LibGit2Sharp.Repository.Clone(
    sourceUrl,
    workingDirectoryPath,
    new CloneOptions
    {
        Checkout = true,
        FetchOptions =
        {
            Prune = true,
            CustomHeaders = new[]
            {
                "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(
                    string.Format(CultureInfo.CurrentCulture, "{0}:{1}", "", _azureDevOpsOptions.PatToken)))
            }
        }
    });

Using just the CredentialProvider I get the error that the OP reported, have a brand new PAT token so I know that's not the issue! So I have some questions because this was working a few months back:

  1. Should the PAT token be base64 encoded in the CredentialProvider?
  2. Does 2FA have any impact on this? Would that be the reason for the original error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants