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 · 34 comments
Closed

Composer Update Fails due to Github Authorization #3542

fiatux opened this issue Dec 12, 2014 · 34 comments

Comments

@fiatux
Copy link

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.

@hkdobrev
Copy link
Contributor

@fiatux
Copy link
Author

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 as completed Dec 12, 2014
@fonsecas72
Copy link
Contributor

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

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

@nmsobri
Copy link

nmsobri 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

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

hugofonseca thanks a lot!

@yoanisgil
Copy link

@hugofonseca Thanks!

@Commifreak
Copy link

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

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

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

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

@midan888
Copy link

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

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

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

@informaticosgb
Copy link

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 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

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 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 commented Oct 21, 2016

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

@breakline87
Copy link

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

@congson95dev
Copy link

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 commented Oct 17, 2018

solution :
just add in composer.json

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

@ew5yte5ye
Copy link

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

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 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 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

@b-hayes
Copy link

b-hayes commented Jul 19, 2021

yeah, I ran into this on composer 2 as well . Have to manually update the token to the auth.json

@PuffPastry
Copy link

PuffPastry commented Oct 29, 2021

This issue just appeared again, was using version 2.0.8 when it happened.

Updated composer using composer self-update to version 2.1.9 but the issue persisted.

Previously set token had expiry date of Sun, Dec 5 2021. Regenerating the token solved the issue.

@MrAnassBaba
Copy link

MrAnassBaba commented Mar 24, 2023

Otherwise run this command composer diagnose to checking composer status.
And check recommendation alert, finally Updated composer using composer using composer self-update

@skdishansachin
Copy link

@fonsecas72 thanks a lot.

@OCHIENGHerman
Copy link

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

@OCHIENGHerman
Copy link

Thanks it worked.

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

No branches or pull requests