'Git hub token contains invalid characters

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



Solution 1:[1]

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]"
    }
  }

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 user1848181