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

Aperta
#1,873 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
csharp, git, github

Direzione di ricerca

Inizia con la configurazione delle credenziali di CloneOptions e PushOptions nell’issue, usando LibGit2Sharp 0.26.2 su .NET 5.0. Riproduci il 403 durante la chiamata a Network.Push e controlla il remote, il refspec e le credenziali coinvolte. Il lavoro è completato quando la modifica in staging può essere sottoposta a commit e inviata al repository GitHub con il token OAuth.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C#
Stelle
3.5k
Fork
925
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di libgit2/libgit2sharp

Tutte le issue di libgit2/libgit2sharp

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.