libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

LibGit2SharpException: could not find appropriate mechanism for credentials

Open MichielOda opened this issue 1 year ago • 5 comments

Reproduction steps

Upgraded from v0.26.2 to v0.30.0, had compilation issues. Fair enough, we were quite out of date. We changed the credentials provider as this was now located in the FetchOptions (see #2065). I even tried setting the ProxyOptions.ProxyType to None as that was now Auto by default.

Has there anything changed regarding credentials between those versions? I didn't immediately spotted something on the releases/changes page.

Expected behavior

Everything keeps working as normal.

Actual behavior

Exception is thrown when trying to clone a repository: LibGit2Sharp.LibGit2SharpException: could not find appropriate mechanism for credentials at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 136 at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in /_/LibGit2Sharp/Core/Proxy.cs:line 278 at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in /_/LibGit2Sharp/Repository.cs:line 810

Version of LibGit2Sharp (release number or SHA1)

v0.30.0

Operating system(s) tested; .NET runtime tested

Windows 11 .NET Framework 4.8

MichielOda avatar Mar 27 '24 13:03 MichielOda

You mentioned #2065 but I think that only applies to proxies? I'm not sure if something else changed. Can you show the set up for your credentials and / or auth callback, and the callback that you're using (if you're using one)?

What kind of provider are you authenticating to? Do you know what mechanism you are expecting to use? (Basic, NTLM, etc)

ethomson avatar Mar 27 '24 13:03 ethomson

In the meantime I tried every version between 0.26.2 & 0.30.0 and it starts to break when I update to 0.29.0. I mention #2065 as that caused breaking changes compilation-wise. But it seemed a very small change to fix it (move CredentialsProvider & OnTransferProgress (2 properties of CloneOptions we used) to the FetchOptions from the CloneOptions).

We use the DefaultCredentials() for the handler: libGitCredHandler = (_url, _user, _cred) => new DefaultCredentials();

And the OnTransferProgress is basically eventing if I understood correctly and is used to show the progress in the UI.

I did the same changes in v0.28.0 as well (moving those to FetchOptions) and everything still works.

MichielOda avatar Mar 27 '24 14:03 MichielOda

I have some small issues with upgradeing my tool here https://github.com/michaelmsonne/GitHubBackupTool to use the new v. as stuff break and is changed - like 'CloneOptions' does not contain a definition for 'RepositoryOperationCompleted' and so on. Have tryed to move to the FetchOptions but not all works..

So for now the tool use v. 0.28

michaelmsonne avatar Mar 30 '24 12:03 michaelmsonne

~Tracking this issue also, I can't set credentials to clone a repo at the moment so I'm going to go to v 0.28~ Found the resolution in the mentioned issue below, we can resolve using:

var cloneOptions = new CloneOptions();
cloneOptions.FetchOptions.CredentialsProvider = ...

davidsr2r avatar Apr 15 '24 02:04 davidsr2r

Any update/idea on why the credentials don't work anymore from 0.29 onwards? We're stuck on 0.28 but as that version has been made deprecated, our security team wants us to update this NuGet.

MichielOda avatar Apr 17 '24 09:04 MichielOda