Composer [UnexpectedValueException] Your github oauth token for github.com contains invalid characters: - composer-php

Here i am.
I already try few answers in StackOverFlow to fix this issue but it didn't work for me and i don't know what else can i do...
So i want to install my project and every time i get this issue
enter image description here
I went to the file auth.json
{"github-oauth": { "github.com": "ghp_uZfXyLME3qawVSyaZGRIhj3upFgaH24JYBn } }
and i took of the "github.com": "ghp_uZfXyLME3qawVSyaZGRIhj3upFgaH24JYBn"
to get
{"github-oauth": { } }
I run composer self:update
I put back the line with the token
I try to install my app
And i get the same issue...
If somebody has anyidea how to fix it ?
I'm working actually with composer 2.1.6

This worked by using:
export COMPOSER_AUTH="{\"http-basic\": {\"github.com\": {\"username\":\"github_username\",\"password\":\"github_token\"}}}"
Note:
Replace (github_username/github_token) by your own credentials

Related

String(4) "asas" is throen in the console while running artisan command laravel

I encountered a strange error today where the error looks like in the image:
I cloned my one of my colleague's repository and ran composer install command.
As it tried to generate optimized files, the error started popping out. After that, if I try to run any artisan command, it throws the same error text string(4) "asas".
To be more precise, I already have .env configured.
Please help. Am I really missing something that I need to look at?
The most likely explanation is that your colleague dumped asas somewhere in the code base. Probably in a place that is loaded everytime you execute a command, like a service provider.
Just search for asas in all files and you'll find something like:
dd('asas');
//or
var_dump('asas');
die;
Since asas is only the result, it may be a variable, like dd($test); where asas is the value.
If you don't find anything, search for dd or var_dump.

meanjs best practice to setup process evn for database

In my attempt to get a 'hello world' skill with meanjs.org product, I cloned 0.4.2 and setup a mongolab account.
I opened > config > env > development.js, to setup db URL, where I have this:
db: {
uri: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean-dev',
For trial, I simply replaced process.env.MONGOLAB_URI with my URL from mongolab and everthing worked for sure, but I doubt this is the way to go. I see a Procfile there, may be I should specify the process.env.MONGOLAB_URI there? Where I could specify it, so that if I upload it to Heroku, say, it will setup the process.env.MONGOLAB_URI and no edit will be needed here please?
p.s. I googled and searched SOF
Well just a small progress,
I got to my gulpfile.js and setup a task as:
gulp.task('setmydb', function () {
process.env.MONGOLAB_URI =
'mongodb://mylogin:mypassword#ds157479.mlab.com:57479/meantst1';
});
Then at the end of the file, added into the task sequence:
// Run the project in development mode
gulp.task('default', function (done) {
runSequence('env:dev', 'lint', ['setmydb','nodemon', 'watch'], done);
});
Well it worked, but I'm still not sure if this indeed is how it must be done! So please help me get sure.
Just in case if someone else also needed, this is how I solved my problem:
Setting configuration variables | Heroku
I first followed the Heroku getting started and edited their app there, added this root:
app.get('/envtst', function(request, response) {
var xterm = process.env.XVAR ==='yes' ? 'yes' : 'no';
response.send(xterm);
});
Then pushed the app to Heroku and also setup my test variable XVAR via command line:
heroku config:set XVAR=yes
finally, opened the root in browser and verified.

Composer [UnexpectedValueException] error will trying to use composer to install a github project

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
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:
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)
Remove its github.com entry. Your file will probably look like the following after removing the entry: {"github-oauth": {}}
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.
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).
I fixed it.
Goto C:\Users\XXXXX\AppData\Roaming\Composer
Open the auth.json
delete the github.com entry under "github-oauth": {}
That's it.
Update answer for Masiorama and Ruchir Mehta:
If you looking for file auth.json but don't know how, use this command:
locate auth.json
And here's the result:
You can see that auth.json will look like this:
/home/{your user name}/.config/composer/auth.json
Then you could use this command to edit the file:
sudo gedit /home/dev/.config/composer/auth.json
And remove content inside github-oauth.
If you're on MacOS, the auth.json file is at ~/.composer/auth.json. Then from there, you can remove the value for github-oauth. I tried fully deleting the file but I got a parse error, Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['. Your auth.json file should look like this:
{
"github-oauth": {}
}
This is similar to other answers posted but I wasn't able to use the locate command on MacOS so this might be helpful to other Mac users
This error recently popped up from nowhere.
Simply deleting the whole auth file worked for me..! Not sure why / when it appeared in the first place.
~/.composer/auth.json
As far as I know (I'm a beginner with composer too), the problem is with your authentication, so you have to fix your credentials in auth.json inside path-to-composer/.composer/
Inside you will find a json which will probably looks like:
{
"github-oauth": {
"github.com": null
}
}
Fix that and you should be ok ;)
The solution is just to upgrade your Composer version
using command composer self-update.
Go to C:\Users\UserName\AppData\Roaming\Composer
Open the auth.json file.
Clear everything and paste the below code
{
"bitbucket-oauth": {},
"github-oauth": {},
"gitlab-oauth": {},
"gitlab-token": {},
"http-basic": {},
"bearer": {}
}
I hope it will be solved
I run in the same problem after upgrading githup api token to the new format.
The answer is you need to upgrade composer version 1.10.21 or higher that fixes this problem.
Same solution as the answer of Paulina Khew but with command lines on MacOS :
cd ~/.composer/
nano auth.json
Delete what is inside th bracket :
{
"github-oauth": {}
}
When you're ready to save the file, hold down the Ctrl key and press the letter O
Press the Enter key on your keyboard to save.
When finished, press Ctrl + X to close nano and return to your shell.
Edit the composer authentication configuration file ~/.composer/auth.json
Then replace the following.
"http-basic": {
"github.com": {
"username": "[YOUR-GITHUB-USERNAME]",
"password": "ghp_[YOUR-PERSONAL-TOKEN]"
}
}
Now run the command composer install
That's a bug.
If you have Debian or Ubuntu, try this patch. Otherwise read the last line.
Quick copy-paste patch
If you have Debian 10 buster or Ubuntu 20.LTS or similar distributions, try this copy-paste command:
wget https://gist.githubusercontent.com/valerio-bozzolan/84364c28a3bba13751c504214016adcf/raw/c1356d529c89c10de4c959058e2e86ffe58fa407/fix-composer.patch -O /tmp/fix-composer.patch
sudo patch /usr/share/php/Composer/IO/BaseIO.php /tmp/fix-composer.patch
If it does not work, write it in the comments.
Step-by-step explaination
Your Composer version has a bug: you are able to save a valid GitHub token, but then it's not able to read that token again because Composer thinks that your GitHub token cannot contain underscores or stuff like that. Moreover, it's strange that Composer checks its syntax only the second time. Why? that's another story.
The fix is simple. You can temporary disable that wrong validation in your Composer version. Also because GitHub is a proprietary service and their specifications can change over time (as you demonstrated today). So it makes sense not to validate the syntax of GitHub tokens. The only person who should hard-validate GitHub tokens is GitHub itself, not Composer.
If you installed Composer via apt install composer, probably you will not have any update available and surely you cannot use self-update because Composer is read-only for security reasons (and for a similar reason, you should not execute Composer from root). Instead, you can create a safe hot-patch to fix that specific issue.
To create a patch, create a file called /tmp/fix-composer.patch with this exact content:
103,105c103,105
< if (!preg_match('{^[.a-z0-9]+$}', $token)) {
< throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
< }
---
> // if (!preg_match('{^[.a-z0-9]+$}', $token)) {
> // throw new \UnexpectedValueException('Your github oauth token for '.$domain.' contains invalid characters: "'.$token.'"');
> //
That content can also be seen from here:
https://gist.github.com/valerio-bozzolan/84364c28a3bba13751c504214016adcf
Then run this command to apply that patch:
sudo patch /usr/share/php/Composer/IO/BaseIO.php /tmp/fix-composer.patch
If it does not work, probably you have not installed composer via apt.
In short, whatever operating system, and whatever installation method, locate the file BaseIO.php in your Composer and comment out the validation check.

Cloud9 tries to recreate .settings file

I've installed Cloud9 IDE on my linux machine in order to play around with it a bit (I had to use nodejs 0.8 because cloud9 uses a package that depends on node-waf, which is no longer supported by higher versions of nodejs).
I can start it up without problems, however when I try to access Cloud9 via browser, it constantly gives me the error message: File already exists.. Here's a trace from the log:
Error: File already exists.
at module.exports.from (/home/xyz/repos/cloud9/node_modules/vfs-local/localfs.js:678:35)
at Object.fs.exists [as oncomplete] (fs.js:91:19)
Relevant code section:
exists(topath, function(exists){
if (options.overwrite || !exists) {
// Rename the file
fs.rename(frompath, topath, function (err) {
if (err) return callback(err);
// Rename metadata
if (options.metadata !== false) {
rename(WSMETAPATH + from, {
to: WSMETAPATH + to,
metadata: false
}, function(err){
callback(null, meta);
});
}
});
}
else {
var err = new Error("File already exists.");
err.code = "EEXIST";
callback(err);
}
When the error occurs, the topath variable is set to the workspace settings file (/home/xyz/repos/cloud9/workspace/.settings)
Has anyone else had an error like this? How can I resolve it?
thx in advance
Reinstalling cloud9
First option, maybe you could try using this workaround installation procedure:
https://github.com/ajaxorg/cloud9/issues/2904#issuecomment-22518669
Second option, if you are willing to always use an older node-version for running cloud9 as you indicated, I used the following installation procedure and it worked (assuming you already installed nvm). Then you can still use the cloud9.sh-file for starting:
git clone git://github.com/ajaxorg/cloud9.git
cd cloud9
nvm install 0.8.8
sed -i -e 's/~//g' package.json
npm config set ca=""
npm install
sed -i s/connect.session.file/connect.session.memory/ configs/default.js
Not sure if 0.8.8 is the best node-version for cloud9 but it works for me :)
Last step seems necessary because of https://github.com/ajaxorg/cloud9/issues/2005#issuecomment-11372587 :)
Then before starting cloud9 you always have to enter:
nvm use 0.8.8
Or you set 0.8.8 as the default node version if you don't use node much otherwise:
nvm alias default 0.8.8
Fix problem without reinstalling
Third option, if you don't want to repeat the installation procedure you could try just reinstalling the vfs-local-module in the cloud9 directory:
npm install vfs-local#0.3.4
Haven't tested this though :)

Heroku error "Unexpected error while processing request: can't convert nil into String"

I have a Sinatra app that is located here https://github.com/trivektor/Backbone-Hangman. The first time I push it to Heroku, everything worked fine. However, on the second push my application crashed. The only thing that I changed was CSS. Checking the logs, I found the message
Unexpected error while processing request: can't convert nil into String
Does anyone know why this is happening? Thanks.
Sometime the lack of a closing } can cause this. Check those in all your css files and prescompile assets for production.
RAILS_ENV=production bundle exec rake assets:precompileHere is some more details
I was getting the same error in a Sinatra app this week. Looking at the git repo provided by this questions author, I saw this commit. It fixed the issue I was having.
I had this issue using sinatra-activerecord. Updating my database and rebooting the environment did the trick for me:
rake db:migrate

Resources