libgit2 / libgit2/libgit2sharp

Fetch and Pull using Personal Access token

Aperta
#1,818 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

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.

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.

Direzione di ricerca

Inizia con CredentialsHandler e UsernamePasswordCredentials passati a Commands.Fetch e Commands.Pull. Riproduci fetch e pull utilizzando le varianti delle credenziali fornite, acquisisci l'errore esatto e determina il comportamento di autenticazione supportato per i personal access token; il lavoro è completato quando entrambe le operazioni eseguono correttamente l'autenticazione.

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

Valutazione

Stack tecnologico
csharp, git
Ambito
authentication, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.