libgit2 / libgit2/libgit2sharp
Impossible to push to Azure repository using Person Access Token
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C#
- Star
- 3.5k
- Fork
- 925
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xem xét PushOptions và so sánh cấu hình khả dụng của nó với FetchOptions, sau đó đọc pull request #2011 và ví dụ trên wiki về git-push. Công việc hoàn tất khi việc push lên một repository Azure có thể truyền PAT dưới dạng header ủy quyền tùy chỉnh mà không gặp lỗi phát lại xác thực; hãy thêm hoặc cập nhật các bài kiểm thử liên quan nếu subsystem hiện có cung cấp chúng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- azure, csharp, git
- Lĩnh vực
- authentication, devtools
- Loại issue
- Tính năng
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100