Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitbucket authentication to use LibGit2Sharp

I used the CSharp.Bitbucket library to authenticate users with Bitbucket (https://github.com/scottksmith95/CSharp.Bitbucket). The authentication works fine, I get the token value and token secret values.

I have alredy written a logic - with the help of LibGit2Sharp (https://github.com/libgit2/libgit2sharp) - to clone/pull/push the content of the users repo. It works fine if the user authenticates with GitHub. In that case I have to provide the value of the access token for username and an empty string for password.

 LibGit2Sharp.Credentials credentials = new UsernamePasswordCredentials()
        {
            Username = [GITHUB ACCESS TOKEN], 
            Password =""
        };

But what about Bitbucket? Can I use LibGit2Sharp in this way? I couldn't find any documentation about this issue. I tried to use the token value and the token secret also for username, but it fails.

enter image description here

I would like to use Bitbucket with Git and Mercurial too. Is there a little trick which I couldn't realize this far?

Thank you for your help!

like image 443
Gábor Domonkos Avatar asked Jun 17 '26 22:06

Gábor Domonkos


1 Answers

This question is old but I will answer for those how come across whith this problem. First, what you have to do is get an acces token. Its well explaned here.

Once you have the token, you can authenticate like this

   CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
        {
            Username = x-token-auth:[ACCES-TOKEN],
            Password = ""
        } 

Hope it helps someone.

like image 77
Rafael Juan Avatar answered Jun 20 '26 14:06

Rafael Juan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!