libgit2 / libgit2/libgit2sharp

How can we commit changes using the access token key that gets generated using oauth support in gitHub

未关闭
#1,873 1 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
C#
星标
3.5k
派生
925
PR 合并指标
30 天内没有已合并 PR

描述

How can we commit changes to github using the access token generated using github Oauth.

I have got the access token and able to clone the repository using the code below
CloneOptions options = new CloneOptions();
var creds = new UsernamePasswordCredentials()
{
Username = "access token"
Password = string.Empty
};
CredentialsHandler credHandler = (_url, _user, _cred) => creds;
options.CredentialsProvider = credHandler;
string clonedRepoPath = Repository.Clone("repository", repoLocation, options);
repo = new Repository(repoLocation);

But unbale to commit the changes using the access token. below code fails with the error "'request failed with status code: 403"

Commands.Stage(repo, "abc.txt");
Signature sig = new Signature(new Identity("name", "email"), DateTimeOffset.Now);
Commit commit = repo.Commit("", sig, sig);

        // Push to remote repository
        var creds = new UsernamePasswordCredentials()
        {
            Username = "access token",
            Password = ""
        };
        CredentialsHandler credHandler = (_url, _user, _cred) => creds;
       
        var fetchOpts = new PushOptions { CredentialsProvider = credHandler };
        repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", fetchOpts);

Expected: Should be able to commit changes using access token.

Version of LibGit2Sharp (release number or SHA1)
LibGit2Sharp.0.26.2

Operating system(s) tested; .NET runtime tested
OSx, .net core 5.0

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中 CloneOptions 和 PushOptions 的凭据设置开始,在 .NET 5.0 上使用 LibGit2Sharp 0.26.2。复现 Network.Push 调用期间的 403,并检查涉及的 remote、refspec 和凭据。当可以使用 OAuth token 将已暂存的更改提交并推送到 GitHub repository 时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp, git, github
领域
authentication
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。