Getting exception "too many redirects or authentication replays"
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",
"[email protected]"), DateTimeOffset.Now);
Commands.Pull(repo, signature, pullOptions);
}
}
private UsernamePasswordCredentials func(string url, string user,
SupportedCredentialTypes types)
{
return new UsernamePasswordCredentials
{
Username = "username",
Password = "password"
};
}
I'm getting the same error as @AndersBillLinden on the Clone request. using LibGit2Sharp v0.28.0 and LibGit2Sharp.NativeBinaries v2.0.320
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:
- Should the PAT token be base64 encoded in the CredentialProvider?
- Does 2FA have any impact on this? Would that be the reason for the original error?