I am trying to programmatically clone a git repository. My ASP.NET MVC application is creating and starting a process. The code to handle the processes works correctly however the authentication is failing when trying to use a TFS on premise PAT to clone a git repository. I cannot use NTLM or require the user to enter credentials. I can confirm my C# code handling creating processes to use the git bash shell programmatically works as I have no issue on my local machine but in production on IIS the issue arises. I have tried the following two methods.
Method 1: git clone http://anyusername:PAT@tfs2017:8080/tfs/DefaultCollection/_git/Git%20Repository
PAT is the token I have generated for my user. I have tried to encode it in base64 as well.
Method 2: As suggested by a person on a MS social forum.
git -c http.extraheader="AUTHORIZATION:bearer {base64encodedPAT}" clone {url}
Original MS Forum Question for Reference: https://social.msdn.microsoft.com/Forums/vstudio/en-US/0107cf1f-7fe4-4429-af74-ca7d2be7405e/using-personal-access-tokens-in-tfs-2017?forum=tfsversioncontrol
Under your GitHub user profile (not the repository profile), click the “Settings” link. Scroll down and click the “Developer Settings” link. Click the GitHub “Personal access tokens” link. Click the “Generate new token” link and provide your password again if required.
On the start window, select Clone a repository. In the Browse a repository section, select Azure DevOps. If you see a sign-in window, sign in to your account. In the Connect to a Project dialog box, choose the repo that you want to connect to, and then select Clone.
If you have a PAT, you should not need a password: the PAT would act as your username.
See if the following works:
git clone http://PAT@tfs2017:8080/tfs/DefaultCollection/_git/Git%20Repository
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With