jspm Unauthorized response for GitHub API - heroku

I think the below should work based on what I've read but I get an error. I'm surely not expected hard code my password in .netrc. I've ran heroku:set JSPM_GITHUB_AUTH_TOKEN obvs! I've not base64 encoded the token, maybe thats the problem
heroku run jspm config registries.github.auth $JSPM_GITHUB_AUTH_TOKEN
$ heroku run jspm init
Running jspm init on test... up, run.7011
ok Verified package.json at package.json
Verified config file at frontend/system.config.js
Looking up loader files...
warn Error on download for github:systemjs/systemjs
Unauthorized response for GitHub API.
Use jspm registry config github to reconfigure the credentials, or update them in your ~/.netrc file.
err TypeError: Cannot read property 'toString' of undefined
at Object.exports.log (/app/node_modules/jspm/lib/ui.js:99:27)
at /app/node_modules/jspm/lib/core.js:361:8
at process._tickCallback (node.js:377:9)

Related

Access Organization repo on Github using Personal Access Token inside Bash script

I'm trying to clone a repo using the following syntax inside a bash script
git clone "https://oauth2:[TOKEN]#github.com/[organization]/$reponame.git $REPOPATH/$reponame"
and I get the following error:
Cloning into 'protos-cusum_hmm-python'...
fatal: unable to access 'https://github.com/[organization]/protos-cusum_hmm-python.git /opt/protolangs/protos-cusum_hmm-python/': The requested URL returned error: 400
when I clone directly from command line git clone https://github.com/[organizaiton]/protos-cusum_hmm-python.git it works fine (presumable because it's using my cached credentials)
Any suggestions?
Edit:
Removed quotations around url (git clone https://oauth2:[TOKEN]#github.com/[organization]/$reponame.git $REPOPATH/$reponame) and now getting
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/fluxusinc/protos-cusum_hmm-python.git/'
EDIT2:
When hardcoded with token:
git clone "https://ghp_...O17xckH#github.com/[organization]/"$reponame".git" $REPOPATH/$reponame
it works, so seems like it's a problem with the YAML
- name: Run proto builder and deploy to repos
env:
P_TOKEN: ${{ secrets.REPO_TOKEN }}
run: |
chmod +x "${GITHUB_WORKSPACE}/build.sh"
"$GITHUB_WORKSPACE/build.sh"
shell: bash
much thanks to #torek....
turns out for whatever reason I had to put the secret in the repo rather than the organization and it worked... not sure why that was the case because github is showing it overriding
MORE INFO:
was able to figure out by setting the secret ACTIONS_STEP_DEBUG to true from here.
yielded
##[debug]Evaluating: secrets.REPO_TOKEN_GRPC
##[debug]Evaluating Index:
##[debug]..Evaluating secrets:
##[debug]..=> Object
##[debug]..Evaluating String:
##[debug]..=> 'REPO_TOKEN_GRPC'
##[debug]=> null
##[debug]Result: null
showing that the token was empty for whatever reason

Is there some problem using pnpm with github packages?

My ~/.npmrc looks like
% cat ~/.npmrc
//npm.pkg.github.com/:_authToken=XXXXXXX
//npmjs.org=true
#1uphealth:registry=https://npm.pkg.github.com/1uphealth
In theory our packages like #1uphealth/foobar get installed from our private github packages repository and this works fine for npm
It seems to match the pnpm docs, here, https://pnpm.io/npmrc#url_authtoken, too.
But I am getting this error,
 ERR_PNPM_FETCH_401  GET https://npm.pkg.github.com/1uphealth/#1uphealth%2Fcore-1upenv-script: Unauthorized - 401
No authorization header was set for the request.
These authorization settings were found:
//npm.pkg.github.com/:_authToken=[hidden]
#1uphealth:registry=https://npm.pkg.github.com/1uphealth

Hugo not using local git config

I'm trying to use a private theme/module with a personal access token. I can get this working by adding the following to my global git config.
git config --global url."https://{USER}:{TOKEN}#github.com".insteadOf "https://github.com"
Then running hugo mod get -u it will pull changes as expected.
I don't want this set in my global config and if I set it locally I get an error, because Go doesn't seem to be using the local config.
Set my configurations locally within the root of the site/repository:
git config --local url."https://{USER}:{TOKEN}#github.com".insteadOf "https://github.com"
Then running hugo mod get -u I get the following error:
go get: module github.com/USER/REPOSITORY: git ls-remote -q origin in /var/folders/26/gqnv01_55p964v8yz39d51fw0000gn/T/hugo_cache/modules/filecache/modules/pkg/mod/cache/vcs/b410fc7b91fbc1121b5f6ec2bb2711c27cd172b4084c213e1430a33cde552597: exit status 128:
remote: Repository not found.
fatal: repository 'https://github.com/USER/REPOSITORY/' not found
How can I get Go/Hugo to use my local git config rather than the global?
From the hugo mod source code, hugo will look for a go.mod in your project:
filepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if info.Name() == "go.mod" {
// Found a module.
dir := filepath.Dir(path)
fmt.Println("Update module in", dir)
Check where your go.mod is, and do (in that go.mod parent folder):
git config -l --show-origin --show-scope
That will tell you if your expected local config is actually there or not.
Look for any .git folder which would indicate a nested git repository/submodule, which would ignore your initial git config --local command
An issue like 34513 seems to suggests though that go mod won't take into account the local repository:
The git configuration only affects operations on the underlying git repo.
The error that you're seeing is coming from before that, when the go command is attempting to resolve the repo for the requested package path.
The official documentation only references the global config .gitconfig.
I solved this by adding a directory replacement mapping to the site’s config, instead of modifying the git url. This points to my locally cloned theme and updates the served site whenever I modify the theme.
module:
imports:
path: 'github.com/[USER]/[REPO-NAME]'
replacements: 'github.com/[USER]/[REPO-NAME] -> ../../[REPO-NAME]/'

AWS S3 rejecting deleteDirectory() request even though delete() works

I'm on a Laravel 5.4 project, and in my composer.json file I'm using the following dependencies:
"league/flysystem-aws-s3-v3": "~1.0",
"aws/aws-sdk-php-laravel": "3.*",
When I try running the below, everything works fine:
Storage::disk('s3')->delete('exports/a_few_subdirectories/file.xls');
However, when I try running this line of code in an Artisan command, I get the below error:
Storage::disk('s3')->deleteDirectory('exports');
Here is the error message I receive:
Aws\S3\Exception\S3Exception Error executing "DeleteObjects" on "https://mybucket.s3.us-west-2.amazonaws.com/?delete"; AWS HTTP error: Client error: `POST https://mybucket.s3.us-west-2.amazonaws.com/?delete` resulted in a `400 Bad Request` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MalformedXML</Code><Message>The XML you provided was not well-formed (truncated...)
MalformedXML (client): The XML you provided was not well-formed or did not validate against our published schema - <?xml version="1.0" encoding="UTF-8"?>
After googling around, I found a couple of users who had this same error for significantly different reasons. One user said they had hit a 1,000 key limit, and another user said they were missing a required parameter in their post request, but these users were both using Ruby and not Laravel. Since I'm using these composer packages, I'm assuming the packages are working correctly, and it also seems like everything on S3 is set up correctly (permissions and security settings, for instance). Another fun fact is that I can successfully use deleteDirectory with the local driver instead of the S3 driver, so deleteDirectory is working in that instance.
Any ideas as to what might be amiss? I'd rather delete the directory than loop through files and delete them one by one on S3. Thanks in advance.

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.

Resources