Git hub token contains invalid characters

Viewed 1061

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

2 Answers

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

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
Related