Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix github oauth token for invalid characters: "__TOKEN__"? [duplicate]

Tags:

composer-php

I am trying to install a Github project using composer and get the following error:

Composer [UnexpectedValueException] Your Github oauth token for github.com contains invalid characters: ""

Can anyone explain what I need to do to correct this error?

I am using the following command:

composer create-project --prefer-dist --stability=dev \
    vova07/yii2-start yii2-start

Thank you.

like image 908
Lloyd Avatar asked May 08 '26 19:05

Lloyd


2 Answers

I started getting a similar error and the reason was that Github recently changed the format of their auth tokens:

https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available/

To resolve the error:

  1. Find the composer/auth.json file (if you're running the project in a container, you'll have to bash into it and find the file in there)
  2. Remove its github.com entry. Your file will probably look like the following after removing the entry: {"github-oauth": {}}
  3. Run composer self-update. The issue got resolved in version 2.0.12. See the first item in the changelog for that version here: https://getcomposer.org/changelog/2.0.12

After that, you can restore your composer/auth.json file to its initial state as the newer version of composer will recognize the new key format.

like image 85
rafaelbiten Avatar answered May 10 '26 20:05

rafaelbiten


You can try Basic Auth instead:

Change this (oauth):

  "github-oauth": {
    "github.com": "ghp_[YOUR-PERSONAL-TOKEN]"
  }

To this (basic auth):

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

You can find instructions on how to create a Personal Access Token

Inspired from github docs. Apparently, you can use Basic Authentication with a Personal Access token instead of oauth in some cases (e.g. like mine: installing a private git repo with composer).

like image 30
kevnk Avatar answered May 10 '26 18:05

kevnk