libgit2 / libgit2/libgit2sharp

Impossible to push to Azure repository using Person Access Token

Aperta
#2,041 2 commenti 0 reazioni 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

My problem is described perfectly here, but I don't think the solution is the correct one, since that would use the credentials stored on the computer as far as I'm aware.

When making git requests to an azure repository with a PAT, it is expected to be passed along as a custom header. (see documentation).

This is possible when doing a Clone operation, since CloneOptions contains FetchOptions, which allows us to set custom headers.

So a clone is perfectly possible as follows:

string encodedToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($":{credentials.PersonalAccessToken}"));
var fetchOptions = new FetchOptions
{
    CustomHeaders = new[] {
        $"Authorization: Basic {encodedToken}"
    }
};
var options = new CloneOptions
{
    CredentialsProvider = (url, usernameFromUrl, types) =>
                    new UsernamePasswordCredentials()
                    {
                        Username = credentials.UserName,
                        Password = credentials.PersonalAccessToken
                    },
    FetchOptions = fetchOptions,
    BranchName = branchName,
    Checkout = true,
    OnCheckoutProgress = (path, completedSteps, totalSteps) =>
        Logger.LogInformation("Clone progress {completed} / {total}", completedSteps, totalSteps),
    RepositoryOperationCompleted = (context) =>
        Logger.LogInformation("Clone completed"),
};

Repository.Clone(Remote, WorkingDirectory, options);

However, when trying to push to this same repository, PushOptions does not expose something similar to include the PAT as header, even though it is stored in the internal data structure since https://github.com/libgit2/libgit2sharp/pull/1233 .

Using the provided example from the wiki
I get the following error:
Unhandled exception: too many redirects or authentication replays | LibGit2Sharp.LibGit2SharpException | too many redirects or authentication replays
Which is the exact same error I was getting when trying to clone without the added custom header.

As far as I can see, there is a PR open that would fix this, but it is not yet merged in: https://github.com/libgit2/libgit2sharp/pull/2011

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 esaminando PushOptions e confrontando la configurazione disponibile con FetchOptions, quindi leggi la pull request #2011 e l’esempio della wiki di git-push. Il lavoro è completato quando un push verso un repository Azure può passare il PAT come intestazione di autorizzazione personalizzata senza errori di ripetizione dell’autenticazione; aggiungi o aggiorna i test pertinenti se il sottosistema esistente li fornisce.

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

Valutazione

Stack tecnologico
azure, csharp, git
Ambito
authentication, devtools
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.