Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer Update Fails due to Github Authorization #3542

Closed
fiatux opened this issue Dec 12, 2014 · 27 comments
Closed

Composer Update Fails due to Github Authorization #3542

fiatux opened this issue Dec 12, 2014 · 27 comments

Comments

@fiatux
Copy link

@fiatux fiatux commented Dec 12, 2014

During composer update I am asked for my github credentials repeatedly. What may be causing this?

An existing OAuth token for Composer is present and will be reused

Could not fetch https://api.github.com/authorizations, enter your GitHub credentials to go over the API >rate limit
The credentials will be swapped for an OAuth token stored in /Users/[USER]/.composer/auth.json, your >password will not be stored
To revoke access to this token you can visit https://github.com/settings/applications

Yes, I am entering my password correct, I have tried several different accounts and I can get authorization from Github if I use curl from cmdline.

@fiatux
Copy link
Author

@fiatux fiatux commented Dec 12, 2014

Not really, solved it by creating new token and adding it to the project's composer.json. I'm not sure why the valid token on /Users/[USER]/.composer/auth.json could not be used.

@fiatux fiatux closed this Dec 12, 2014
@fonsecas72
Copy link
Contributor

@fonsecas72 fonsecas72 commented Dec 12, 2014

I'm not sure why the valid token on /Users/[USER]/.composer/auth.json could not be used.

Maybe due to current user or COMPOSER_HOME environment variable at the time of the composer install being different of the expected?
I think I stumbled to something like that before.

@hamiltont
Copy link

@hamiltont hamiltont commented Dec 19, 2014

solved it by creating new token and adding it to the project's composer.json

Could someone post the format of how to do this? I'm experiencing a similar problem and wish to solve it manually for the moment

@slier81
Copy link

@slier81 slier81 commented Dec 19, 2014

Could someone post the format of how to do this? I'm experiencing a similar problem and wish to solve it manually for the moment

Yes, i want to know too

@fonsecas72
Copy link
Contributor

@fonsecas72 fonsecas72 commented Dec 19, 2014

You can solve it by creating a new github token to authenticate your composer requests.
You can do this two ways:

By defining your token globally:

composer config --global github-oauth.github.com <TOKEN>

Or by defining your token in a project composer.json:

{  
  "config": {
    "github-oauth": {
      "github.com": "<TOKEN>"
      }
    }
}

More information about the problem and how to generate github tokens:
Composer troubleshooting

@energysx
Copy link

@energysx energysx commented Dec 25, 2014

hugofonseca thanks a lot!

@yoanisgil
Copy link

@yoanisgil yoanisgil commented Jan 2, 2015

@hugofonseca Thanks!

@Commifreak
Copy link

@Commifreak Commifreak commented Jan 8, 2015

The global Token config does not work (as mentiod in Post 3):

C:\Users\robin.kluth>composer diag
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity: OK
Checking HTTP proxy: OK
Checking HTTP proxy support for request_fulluri: OK
Checking HTTPS proxy support for request_fulluri:
Could not fetch https://api.github.com/repos/Seldaek/jsonlint/zipball/1.0.0, ent
er your GitHub credentials to go over the API rate limit
The credentials will be swapped for an OAuth token stored in C:/Users/robin.klut
h/AppData/Roaming/Composer/auth.json, your password will not be stored
To revoke access to this token you can visit https://github.com/settings/applica
tions
Username:

while in %appdata%\Composer\auth.json:

{
    "http-basic": {},
    "github-oauth": {
        "github.com": "my_token"}
}

If I add the token to projects composer.json, it is working as expected.

@webdevilopers
Copy link

@webdevilopers webdevilopers commented Jan 15, 2015

So the solution is to put the token into the composer.json directely instead of relying on the auth.json?

Will this be solved as suggested in the latest issue #3566 @Seldaek ?

Because as Malcolm Fell @emarref mentions:
If you're working on a collaborative project, you should not commit your key in the project source control. The alternative is to set your key in your home directory...
https://coderwall.com/p/kz4egw/composer-install-github-rate-limiting-work-around

@Commifreak
Copy link

@Commifreak Commifreak commented Jan 15, 2015

Hi,

I figured out, that the auto-generated token (via composer) ist not accepted. If I create the key via GitHub's WebUI and replace the old one in composer.json, it is working.

@webdevilopers
Copy link

@webdevilopers webdevilopers commented Jan 15, 2015

Have you tried that within the auth.json or config.json too?

@midan888
Copy link

@midan888 midan888 commented Jan 21, 2015

I generated new token on Gtihub and pasted this in ocmposer json of the project and it worked, thanks to hugofonseca
{ "config": { "github-oauth": { "github.com": "<TOKEN>" } } }

@webdevilopers
Copy link

@webdevilopers webdevilopers commented Jan 22, 2015

Ok, so the important point is that the token has to be added to the `composer.json' file.

The attempt with auth.son of Composer is no longer supported by the curernt GitHub API:
#3566

@webdevilopers
Copy link

@webdevilopers webdevilopers commented Jan 29, 2015

It looks like @Seldaek added a fix for the original issue by @fiatux :
#3651

@informaticosgb
Copy link

@informaticosgb informaticosgb commented May 26, 2015

Gracias fonsecas72, funciona :D

composer clear-cache

composer global require "fxp/composer-asset-plugin:1.0.0-beta4"

composer config --global github-oauth.github.com "my_token"

composer create-project --prefer-dist yiisoft/yii2-app-advanced yii-application

Así me funcionó para Yii2 Advanced Template.

@Peter74
Copy link

@Peter74 Peter74 commented Jun 21, 2015

Hi I was face same problem.
Solution for me was:

composer config --global github-oauth.github.com <TOKEN>

thanks @fonsecas72
...and as a result of it was writing token at auth.json :

{  
  "config": {
    "github-oauth": {
      "github.com": "<TOKEN>"
      }
    }
}

...but not in composer.json - that was just mistake in explanation, but if you run

composer config --global github-oauth.github.com <TOKEN>
  • you will be OK.
@marcozs84
Copy link

@marcozs84 marcozs84 commented Sep 3, 2015

Posted by codekman at

http://www.yiiframework.com/forum/index.php/topic/60340-issue-while-installing-yii-2/

Please see the line above the cmd, here you will find the url and visit this url and you will git the token and paste the token.

  • it worked for me at least
@o5
Copy link

@o5 o5 commented Oct 20, 2016

Is possible to remove auth token via composer config -g command? I mean something like composer config -g --unset repositories.foo but for auth.json.

Sure, I can remove by fe jg but build-in support in composer should be cool.

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Oct 21, 2016

This will do it for example: composer config --global --auth --unset github-oauth.github.com

@breakline87
Copy link

@breakline87 breakline87 commented Apr 16, 2018

Can you guys make something which works without extensive modifications even for a beginner?

@saxsax1995
Copy link

@saxsax1995 saxsax1995 commented Aug 27, 2018

solved by use this cmd: composer config --global --auth github-oauth.github.com
for example : composer config --global --auth github-oauth.github.com 123456

@alenux
Copy link

@alenux alenux commented Oct 17, 2018

solution :
just add in composer.json

"config": {
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},

@ew5yte5ye
Copy link

@ew5yte5ye ew5yte5ye commented Dec 1, 2019

If you are facing Github token error then open composer.json file and paste below code

"github-oauth": {
"github.com": ""
}

into

"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"github-oauth": {
"github.com": ""
}
}

And then update composer

composer update

If you don't have Github token then first login to github.com and generate token and use ablove steps.

@mijaelsaban
Copy link

@mijaelsaban mijaelsaban commented Apr 8, 2021

The issue is that my token it has an underscore which is never valid according to this logic.

Which here it fails.

 
foreach ($githubOauth as $domain => $token) {
            if (!preg_match('{^[.a-z0-9]+$}', $token)) {
                throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
            }
            $this->checkAndSetAuthentication($domain, $token, 'x-oauth-basic');
        }

@Seldaek
Copy link
Member

@Seldaek Seldaek commented Apr 9, 2021

@mijaelsaban make sure you update Composer to the latest version before reporting error, this was fixed last week.

@Boby
Copy link

@Boby Boby commented Apr 10, 2021

I am running on composer 2 and having this issue, anyway we can remove it make it just ask for auth again? as I am running in docker and cant get it cleaned up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet