libgit2 / libgit2/libgit2sharp
Fetch and Pull using Personal Access token
未关闭
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 3.5k
- 派生
- 925
- PR 合并指标
- 30 天内没有已合并 PR
描述
I'm trying to fetch and pull everytime a request come to the application. So basically im using my own username and password for the same as of now. But when i try to implement it with my personal access token, it throws error.
var path = "my local drive path";
using (var repo = new Repository(path))
{
FetchOptions options = new FetchOptions();
options.CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
new UsernamePasswordCredentials()
{
Username="xxxxx@yyy.com",
Password = githubtoken //my personal token
});
foreach (Remote remote in repo.Network.Remotes)
{
IEnumerable<string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
}
}
//Console.WriteLine(logMessage);
using (var repo = new Repository(path))
{
// Credential information to fetch
LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
options.FetchOptions = new FetchOptions();
options.FetchOptions.CredentialsProvider = new CredentialsHandler(
(url, usernameFromUrl, types) =>
new UsernamePasswordCredentials()
{
Username = "xxxx@yyy.com",
Password = githubtoken //my personal token
});
// User information to create a merge commit
var signature = new LibGit2Sharp.Signature(
new Identity("xxxx", "xxxx@yyy.com"), DateTimeOffset.Now);
// Pull
Commands.Pull(repo, signature, options);
}
I tried replacing the token in place of the username and giving empty string in place of password. Still i'm getting the same error.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从传递给 Commands.Fetch 和 Commands.Pull 的 CredentialsHandler 与 UsernamePasswordCredentials 开始。使用提供的凭据变体重现 fetch 和 pull,捕获确切的错误,并确定受支持的 personal-access-token 身份验证行为;当两个操作都成功完成身份验证时即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, git
- 领域
- authentication, tooling
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100