Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

composer asking oauth token for download public repo

My PHP project has a dependency on a nice library php-sql-query-builder. However, this library has a bug. So I fork the library from it github source to my github account at https://github.com/mmuhasan/php-sql-query-builder and fix the bug in a branch named "dev-where-bug-fix". Then I updated my my project composer file as following:

....
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/mmuhasan/php-sql-query-builder"
    }
],
"require":{
    "nilportugues/sql-query-builder" : "dev-where-bug-fix"
},
....

When I run composer update it ask for a oAuth token as follows:

Could not fetch https://api.github.com/repos/mmuhasan/php-sql-query-builder/contents/composer.json?ref=3dca30b0eaee835783fa61286a51dda425cd3838, please create a GitHub OAuth token to go over the API rate limit
Head to https://github.com/settings/tokens/new?scopes=repo&description=Composer+on+LAPTOP-056S12EK+2018-03-27+1845 to retrieve a token. 

Since my fork is in public, and I want it to be public, why composer is asking token. Any help will be very much appreciated.

like image 371
Md Monjur Ul Hasan Avatar asked Mar 27 '18 17:03

Md Monjur Ul Hasan


People also ask

How do I get my GitHub Oauth token?

In the upper-right corner of any page, click your profile photo, then click Settings. In the left sidebar, click Developer settings. In the left sidebar, under Personal access tokens, click Tokens (classic). Select Generate new token, then click Generate new token (classic).

How do I fix my GitHub Oauth token for GitHub com contains invalid characters?

The solution is to update Composer to the latest version, which supports the new token format, as suggested by Jordi Boggiano on this tweet. "Composer 1.10. 21 and 2.0. 12 (both released April 1st) added support for the new GitHub token format."

Where is composer AUTH json in Windows?

In this authentication storage method, an auth. json file will be present in the same folder as the projects' composer. json file. You can either create and edit this file using the command line or manually edit or create it.


1 Answers

This has nothing to do with public vs. private GitHub repositories. You're hitting GitHub's API rate limit.

From Composer's troubleshooting guide:

API rate limit and OAuth tokens

Because of GitHub's rate limits on their API it can happen that Composer prompts for authentication asking your username and password so it can go ahead with its work.

If you would prefer not to provide your GitHub credentials to Composer you can manually create a token using the following procedure:

  1. Create an OAuth token on GitHub. Read more on this.
  2. Add it to the configuration running composer config -g github-oauth.github.com <oauthtoken>

Now Composer should install/update without asking for authentication.

like image 69
Chris Avatar answered Sep 19 '22 15:09

Chris