libgit2 / libgit2/libgit2sharp
Impossible to push to Azure repository using Person Access Token
まだ誰も着手していません。
- 主要言語
- C#
- スター
- 3.5k
- フォーク
- 925
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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 expected to be passed along as a custom header. (see documentation).
This is possible when doing a Clone operation, since CloneOptions contains FetchOptions, which allows us to set custom headers.
So a clone is perfectly possible as follows:
string encodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($":{credentials.PersonalAccessToken}"));
var fetchOptions = new FetchOptions
{
CustomHeaders = new[] {
$"Authorization: Basic {encodedToken}"
}
};
var options = new CloneOptions
{
CredentialsProvider = (url, usernameFromUrl, types) =>
new UsernamePasswordCredentials()
{
Username = credentials.UserName,
Password = credentials.PersonalAccessToken
},
FetchOptions = fetchOptions,
BranchName = branchName,
Checkout = true,
OnCheckoutProgress = (path, completedSteps, totalSteps) =>
Logger.LogInformation("Clone progress {completed} / {total}", completedSteps, totalSteps),
RepositoryOperationCompleted = (context) =>
Logger.LogInformation("Clone completed"),
};
Repository.Clone(Remote, WorkingDirectory, options);
However, 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 .
Using the provided example from the wiki
I get the following error:
Unhandled exception: too many redirects or authentication replays | LibGit2Sharp.LibGit2SharpException | too many redirects or authentication replays
Which is the exact same error I was getting when trying to clone without the added custom header.
As 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず PushOptions を確認し、利用可能な設定を FetchOptions と比較してから、pull request #2011 と git-push wiki の例を読んでください。Azure リポジトリへの push で、認証の再試行エラーなしに PAT をカスタム認証ヘッダーとして渡せるようになれば作業は完了です。既存のサブシステムに関連するテストがある場合は、それらを追加または更新してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- azure, csharp, git
- 領域
- authentication, devtools
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100