Title: Impossible to push to Azure repository using Person Access Token · Issue #2041 · libgit2/libgit2sharp · GitHub
Open Graph Title: Impossible to push to Azure repository using Person Access Token · Issue #2041 · libgit2/libgit2sharp
X Title: Impossible to push to Azure repository using Person Access Token · Issue #2041 · libgit2/libgit2sharp
Description: My problem is described perfectly here, but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware. When making git requests to an azure repository with a PAT, it is...
Open Graph Description: My problem is described perfectly here, but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware. When making git requests ...
X Description: My problem is described perfectly here, but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware. When making git r...
Opengraph URL: https://github.com/libgit2/libgit2sharp/issues/2041
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Impossible to push to Azure repository using Person Access Token","articleBody":"My problem is described perfectly [here](https://stackoverflow.com/questions/71126033/libgit2sharp-how-to-push-a-local-repo-commit-to-azure-devops-remote-repo-using), but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware.\r\n\r\nWhen making git requests to an azure repository with a PAT, it is expected to be passed along as a custom header. (see [documentation](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops\u0026tabs=Windows#use-a-pat)).\r\n\r\nThis is possible when doing a Clone operation, since CloneOptions contains FetchOptions, which allows us to set custom headers.\r\n\r\nSo a clone is perfectly possible as follows:\r\n```cs\r\nstring encodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($\":{credentials.PersonalAccessToken}\"));\r\nvar fetchOptions = new FetchOptions\r\n{\r\n CustomHeaders = new[] {\r\n $\"Authorization: Basic {encodedToken}\"\r\n }\r\n};\r\nvar options = new CloneOptions\r\n{\r\n CredentialsProvider = (url, usernameFromUrl, types) =\u003e\r\n new UsernamePasswordCredentials()\r\n {\r\n Username = credentials.UserName,\r\n Password = credentials.PersonalAccessToken\r\n },\r\n FetchOptions = fetchOptions,\r\n BranchName = branchName,\r\n Checkout = true,\r\n OnCheckoutProgress = (path, completedSteps, totalSteps) =\u003e\r\n Logger.LogInformation(\"Clone progress {completed} / {total}\", completedSteps, totalSteps),\r\n RepositoryOperationCompleted = (context) =\u003e\r\n Logger.LogInformation(\"Clone completed\"),\r\n};\r\n\r\nRepository.Clone(Remote, WorkingDirectory, options);\r\n```\r\n\r\nHowever, when trying to push to this same repository, PushOptions does not expose something similar to include the PAT as header, even though it is stored in the internal data structure since https://github.com/libgit2/libgit2sharp/pull/1233 .\r\n\r\nUsing the provided example from the [wiki](https://github.com/libgit2/libgit2sharp/wiki/git-push)\r\nI get the following error:\r\n`Unhandled exception: too many redirects or authentication replays | LibGit2Sharp.LibGit2SharpException | too many redirects or authentication replays`\r\nWhich is the exact same error I was getting when trying to clone without the added custom header.\r\n\r\nAs far as I can see, there is a PR open that would fix this, but it is not yet merged in: https://github.com/libgit2/libgit2sharp/pull/2011\r\n\r\n","author":{"url":"https://github.com/TackyTortoise","@type":"Person","name":"TackyTortoise"},"datePublished":"2023-06-06T14:52:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2041/libgit2sharp/issues/2041"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d8c235a5-36d3-597a-c145-10d3ae86addc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E3EA:13AA49:639820A:80E7E0E:697E195B |
| html-safe-nonce | 1b56d08c6740fc43454a4841c3993b680b0a7d6cb54a8f3da51686efa5e5373e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFM0VBOjEzQUE0OTo2Mzk4MjBBOjgwRTdFMEU6Njk3RTE5NUIiLCJ2aXNpdG9yX2lkIjoiODE0NTc1MjkxNDQ2NzI5MDUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f3a04e1f9bef720ac220bcfece0d82b36c8c944c4b101d02019117a4e874eba6 |
| hovercard-subject-tag | issue:1744040626 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/libgit2/libgit2sharp/2041/issue_layout |
| twitter:image | https://opengraph.githubassets.com/72f7032631c8a8ae811e53641eef684a0b9177146d66c678317a9ecc5e1db446/libgit2/libgit2sharp/issues/2041 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/72f7032631c8a8ae811e53641eef684a0b9177146d66c678317a9ecc5e1db446/libgit2/libgit2sharp/issues/2041 |
| og:image:alt | My problem is described perfectly here, but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware. When making git requests ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TackyTortoise |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/libgit2/libgit2sharp git https://github.com/libgit2/libgit2sharp.git |
| octolytics-dimension-user_id | 394745 |
| octolytics-dimension-user_login | libgit2 |
| octolytics-dimension-repository_id | 1415168 |
| octolytics-dimension-repository_nwo | libgit2/libgit2sharp |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1415168 |
| octolytics-dimension-repository_network_root_nwo | libgit2/libgit2sharp |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width