octokit / octokit.net

A GitHub API client library for .NET
https://octokitnet.readthedocs.io/en/latest/
MIT License
2.7k stars 1.08k forks source link

Using "Personal Access Tokens" #812

Closed ghost closed 9 years ago

ghost commented 9 years ago

I have been developing an ASP.NET site that uses Octokit but kept falling foul of the API limits. To help with this I decided to create a "Personal Access Token" in GitHub as I understand that ups your API usage allowance.

The code I now use is

        client = new GitHubClient(new ProductHeaderValue("OMHToken"));
        client.Credentials = new Credentials("<<my token here>>");

This seemed to have no effect, am I using the token in the correct place?

shiftkey commented 9 years ago

The API only differentiates between authenticated and unauthenticated requests:

For requests using Basic Authentication or OAuth, you can make up to 5,000 requests per hour. For unauthenticated requests, the rate limit allows you to make up to 60 requests per hour.

Are you not seeing that occur when the request passes through Fiddler?

ghost commented 9 years ago

So a bit more investigation...

The test code I have is

        client = new GitHubClient(new ProductHeaderValue("OMHToken"));
        client.Credentials = new Credentials("cdaapi", "<<password>>");
        Task<IReadOnlyList<RepositoryContent>> xx = client.Repository.Content.GetAllContents("openEHR", "CKM-mirror", "local/archetypes/" + routePathid + "/");
        IReadOnlyList<RepositoryContent> myList = await xx;

When this code is executed Fiddle shows two calls to the API

 #  Result  Protocol    Host    URL Body    Caching Content-Type    Process Comments       Custom   
 1056   302 HTTPS   api.github.com  /repos/openEHR/CKM-mirror/contents/local/archetypes/demographic/    0       text/html;charset=utf-8   iisexpress:7824           
 1091   200 HTTPS   api.github.com  /repositories/5150654/contents/local/archetypes/demographic 3,257   public, max-age=60, s-maxage=60 application/json; charset=utf-8 iisexpress:7824         

The first call has the Authorization Header set, the returning headers show X-RateLimit-Limit: 5000 However the second call has no Authorization Header set and as such has X-RateLimit-Limit: 60

The HTTP response on the first call is a 302 suggesting a redirect to a different URL, in doing so it is dropping the auth credentials.

darrelmiller commented 9 years ago

This is a known issue with redirects. There is a PR in the works to fix this issue #808