libgit2 / libgit2/libgit2sharp

Fetch and Pull using Personal Access token

Offen
#1,818 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
3.5k
Forks
925
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem CredentialsHandler und UsernamePasswordCredentials, die an Commands.Fetch und Commands.Pull übergeben werden. Reproduziere fetch und pull mit den bereitgestellten Credential-Varianten, erfasse den genauen Fehler und ermittle das unterstützte Authentifizierungsverhalten für Personal Access Tokens; abgeschlossen ist die Aufgabe, wenn sich beide Vorgänge erfolgreich authentifizieren.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp, git
Bereich
authentication, tooling
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.