6

I usually connect to my website's web host using a windows power shell terminal.

While trying to update composer using "composer self-update --2" command, I am getting the error as follows

Your github OAuth token for github.com contains invalid characters

I have checked for auth.json where composer.json file located but I could not find it.
So I tried to update the token using the command prompt but nothing worked.

I have attached the error image please check, and any help would be appreciable.

Error Image

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
sam
  • 127
  • 1
  • 5

3 Answers3

3

It may depend on your composer version.

As shown in this article by Nono Martínez Alonso:

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

  • Go to getcomposer.org/download/
  • Follow the instructions to download the latest phar

And in your auth.json:

 "http-basic": {
    "github.com": {
      "username": "[YOUR-GITHUB-USERNAME]",
      "password": "ghp_[YOUR-PERSONAL-TOKEN]"
    }
  }

Alex Gusev suggests in the comments:

  • try to add your username & OAuth token into ~/.composer/auth.json
  • use -n option with composer: composer -n ...
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your response. Unfortunately, I do not have a auth.json file. I have checked in the places where auth.json file should be. I am trying to create one using composer but it is giving that above error. – sam Jan 28 '22 at 10:35
  • @mik OK. What version of OS, git and composer do you have? – VonC Jan 28 '22 at 10:55
  • @mik OK. Any chance you could upgrade composer to 2.2.5? And Git to 2.35.0? (throug ppa: https://stackoverflow.com/a/41357503/6309) – VonC Jan 28 '22 at 18:23
  • Hi @VonC, These are the current versions The Apache version is: 2.4.52 The Ubuntu Version is: 18.04.6 composer: 1.10.12 and for git it is: 2.17.1 – sam Jan 28 '22 at 18:24
  • Hi @VonC, I have followed the details in the link you have provided, but getting the bash "bash: sudo: command not found" tried to install bash using "apt-get install sudo -y" even for that got "bash: apt-get: command not found". even tried su - but he result is same bash. Can please give me some more other possible solutions – sam Jan 30 '22 at 21:22
  • @mik regaridng sudo, check first https://unix.stackexchange.com/a/428976/7490 – VonC Jan 30 '22 at 21:44
  • try to add your username & OAuth token into `~/.composer/auth.json` as mentioned by @VonC and use -n option with composer: `composer -n ...` – Alex Gusev Aug 18 '22 at 12:30
  • 1
    @AlexGusev Thank you for this feedback. I have included your comment in the answer for more visibility. – VonC Aug 18 '22 at 12:55
1

github changed their token format and composer checks the format before calling out to github via regexp. Older versions of composer won't recognize the new token format. Updating composer will fix the issue:

composer self-update
  • ... the question is how can you update when `composer self-update` is failing with an error. So obviously that can't be the fix. – Abhi Beckert Jun 07 '23 at 00:52
0

Nothing will be fixed until you will not run the `composer self-update' command into the parent directory of your server. Into the project, root composer will always be failed in this specific case.

Composer Path: /usr/local/bin

AuthJson Path: /opt/bitnami/php/composer/auth.json