libgit2 / libgit2/libgit2sharp
Fetch and Pull using Personal Access token
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CredentialsHandler and UsernamePasswordCredentials passed to Commands.Fetch and Commands.Pull. Reproduce the fetch and pull using the provided credential variants, capture the exact error, and determine the supported personal-access-token authentication behavior; done means both operations authenticate successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- authentication, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100