github git-credential: "erase" operation not supported - github-cli

I have some trouble with the github repository I am working on.
I just realised I am 3 commits ahead of main and wanted to push, but the terminal prompted the following:
git push
gh auth git-credential: "erase" operation not supported
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/name/project/'
Has anyone encountered this before and can help?
Many thanks

You need to re-authenticate with GitHub. Run the following command and follow the prompts.
gh auth login

The accepted answer didn't work for me.
I had to do gh auth refresh instead.

Unfortunately both gh auth login and gh auth refresh don't work for me. gh auth status shows that I'm logged in.
This came up for me on git pull and it's only happening on one repository out of many. I also haven't touched this repository for at least 3 months, so I deleted the whole folder from my local and cloned the repo again.
This fixed the issue for me.

Just in case it helps anybody.
I have faced the same problem while executing a git push.
This situation has been this:
I use the same laptop for my usual day-work and my personal work. I have separate github accounts (usernames, emails etc.) for each of these two.
I write some code. I want to check in to a repository in my personal github.com account.
I do necessary housekeeping (commit, status, log etc.), to ensure that I am ready to push to my personal github account.
I do a git push, and I am reprimanded:
remote: Permission to {my personal github username}/-------.git denied to
{my workplace github username}.
fatal: unable to access
'https://github.com/{my personal github username}/-------.git/'': The
requested URL returned error: 403
From the same laptop, I submit code my workplace github too, and for good reasons, that username is the default on my laptop. So, I understand that I have to override that.
After some exploration - including visiting this page on Stackoverflow - and trying out a few things, I have taken the following steps:
First, use the gh, the github CLI tool (version 1.9.2 (2021-04-20), on Ubuntu 22.10), to check which user's credentials is being taken up by git, at the moment:
nirmalya#bluewhale:attempt_2_tac$ gh auth status
github.com
✓ Logged in to github.com as {my workplace github username} (/home/nirmalya/.config/gh/hosts.yml)
✓ Git operations for github.com configured to use https protocol.
✓ Token: *******************
The output underscores the reason behind that dour response to my git push earlier.
Second, ensure that this session is brought down.
nirmalya#bluewhale:attempt_2_tac$ gh auth logout
? Are you sure you want to log out of github.com account '{my workplace github username}'? Yes /* <- default response */
✓ Logged out of github.com account '{my workplace github username}'
I am in the clear. I must be able to push now! Nah!
nirmalya#bluewhale:attempt_2_tac$ git push
Username for 'https://github.com': {my personal github username}
Password for 'https://{my personal github username}#github.com': /* I type in the password */
gh auth git-credential: "erase" operation not supported
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/{my personal github username}/whatever.git/
Third, I set myself up for a fresh login:
nirmalya#bluewhale:attempt_2_tac$ gh auth login
? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? How would you like to authenticate GitHub CLI? Login with a web browser
! First copy your one-time code: D823-F390
- Press Enter to open github.com in your browser...
Opening in existing browser session.
/* at this point I move to browser and log in using my usual 2FA authentication scheme */
✓ Authentication complete. Press Enter to continue...
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as {my prsonal github username}
Now, I am all set to push to github, it seems:
nirmalya#bluewhale:attempt_2_tac$ git push
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 1.46 KiB | 1.46 MiB/s, done.
Total 9 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/{my personal github username}/whatever.git
aa6dc4f..b04f5e7 main -> main
Phew! :-)
Hopefully, this will save someone's time.

In my case, none of the other answers seemed to work.
My repo was last accessed by me 3 months ago, and since then, my Personal Access Token (PAT) expired.
I also realized that my PAT was hard-coded into one of the files. So, in my case, I fixed it by following procedure:
I created a new PAT by logging into Github in browser and going to Settings > Developer Settings > Personal access tokens > Tokens (classic) and using the Generate new token button.
I copied the generated token.
In my local directory, I went to the following file in my git synced folder: .git/config.
Under [remote "origin"], the url was something like: https://username:old_PAT#github.com/username/repo-name.git. I modified it by changing old_PAT to new_PAT and saving the file.
Then, running git pull origin main in Terminal worked for me.

Related

Create Shopify Custom App with webhook in 2022

I want to create a quite simple Shopify Custom App for my shop. This App should run when an order is created, so with a webhook product/change.
After creating the webhook, I receive errors in my terminal as soon as I update a product and the webhook is sent. I just have no idea how to correctly implement the webhook code and where. So this question here is a very basic question, how can I implement a Shopify webhook (webhook code from official Shopify dev page for Ruby) in my freshly Shopify CLI created app. Unfortunately, I can't find any help, it seems that there are so many different ways of creating webhooks. None of them is working for me so far, so I try to stick to the most common one described by shopify dev tutorials.
Steps so far:
I installed a custom app with Shopify CLI, using a Node template with the command "npm init #shopify/app#latest". After this, with "npm run dev" I created a tunnel with ngrok. With this, I receive a url to the app, I can access the app in my Shopify Partners and install it.There is a video tutorial of a shopify dev that I used as help, if someone is more interested Shopify dev Webhook tuorial (of 2021, so I guess a bit outdated unfortunately).
I put the following "webhook code", which uses Ruby, in a app.rb file, which I saved in my root folder of my Shopify CLI created app. The code is available in Shopify dev tutorials (Shopify dev tuorial) for Ruby (I made just very few adaptions like adding a path and adding the Shopify Secret Key:
require 'rubygems'
require 'base64'
require 'openssl'
require 'sinatra'
require 'active_support/security_utils'
# The Shopify app's API secret key, viewable from the Partner Dashboard. In a production environment, set the API secret key as an environment variable to prevent exposing it in code.
API_SECRET_KEY = 'my_api_secret_key'
helpers do
# Compare the computed HMAC digest based on the API secret key and the request contents to the reported HMAC in the headers
def verify_webhook(data, hmac_header)
calculated_hmac = Base64.strict_encode64(OpenSSL::HMAC.digest('sha256', API_SECRET_KEY, data))
ActiveSupport::SecurityUtils.secure_compare(calculated_hmac, hmac_header)
end
end
# Respond to HTTP POST requests sent to this web service
post '/webook/product_update' do
request.body.rewind
data = request.body.read
verified = verify_webhook(data, env["HTTP_X_SHOPIFY_HMAC_SHA256"])
halt 401 unless verified
# Process webhook payload
# ...
end
Next to the "app.rb" in the root folder of my App, I created a "Gemfile":
source 'https://rubygems.org'
gem 'shopify_api'
gem 'sinatra'
gem 'activesupport'
With bundle install, a Gemfile.lock is created, everything seems fine here. I created a webhook for product_change in my Shopify Partners Admin under "Notifications". As URL, I entered the ngrok URL from terminal window (from npm run dev command, the tunnel is still open), but with adding /webook/product_update, as this I used in the function path of the webhook.The webhook is sending sth to my app when I update a product, which is good at least. Unfortunately, as I update a product, my app shows errors in the terminal and crashes. The same errors are appearing even if I delete the app.rb file and the Gemlock files completely.The terminal shows these errors:
C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:13
var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(args), false)) || this;
**InvalidRequestError: Request does not contain a host query parameter**
at InvalidRequestError.ShopifyError [as constructor] (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:13:28)
at new InvalidRequestError (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\error.js:230:42)
at Object.getEmbeddedAppUrl (C:\ShopifyApps\test2\web\node_modules\#shopify\shopify-api\dist\utils\get-embedded-app-url.js:22:15)
at file:///C:/ShopifyApps/test2/web/index.js:187:41
I'd be very happy about any hint how to find out what is wrong. How can I connect the abb.rb file with my index.js file of my root app? I guess I need to do that. But I have no real idea unfortunately.

How to anbale cookies for gitlab OAuth when running cypress test

I have an angular app which has to authorize to gitlab and signIn the user with userName and pass in order to fetch some data/information from gitlab and display it in the UI.
The first test case fails before the browser can redirect to the gitlab login-form (https://gitlab.com/users/sign_in):
Spec Code:
it('Visits the home page', () => {
cy.visit('/', {
onBeforeLoad(win) {
cy.stub(win.navigator, 'cookieEnabled', false).as('cookieEnabled');
},
})
})
Error:
Checking your browser before accessing gitlab.com.
Please enable Cookies and reload the page.
This process is automatic. Your browser will redirect to your requested content shortly.
Please allow up to 5 seconds…
I have been searching and trying couple of other options/implementation based on cypress official doc etc., but still facing the same issue. Some kind of similar questions here in SO, but none for the hints/answers provide the fix.
Also I am not 100% sure that it's really an issue related to cypress test implementation. Could it be an issue affecting gitlab itself?
Any ideas how to fix such issue?
Cypress: 10.7.0
Angular: 14.x
Node: v16.13.1

Github Api list commit status when repository is under organisation

I am trying to list status of commits for a repository using github rest api.
The repository is under organisation and is private.
The repos_url of which is https://api.github.com/orgs/mydummyorg/repos
Users with pull access can view commit statuses for a given ref:
GET /repos/:owner/:repo/commits/:ref/statuses
As per the api above is the GET url
So my final url will be repos_ulr + :owner/:repo/commits/:ref/statuses
If I do the curl as below then it is giving 404 not found
curl -u "username" https://api.github.com/orgs/mydummyorg/repos/:owner:repos/commits/:ref/statuses
Where:
:owner = username (my login id in git)
:repos = repository name under 'mydummyorg
:ref = sha of the commit`
I don't know what am I doing wrong. Is my url proper?
And the value that I am passing for :owner , :repos, :ref correct?
All I can see is:
in your curl, you mention :owner:repos instead of :owner/:repos (maybe a typo in your question, or you forgot a '/')
GET /repos/:owner/:repo/commits/:ref/statuses means the "List Statuses for a specific Ref" API should be
https://api.github.com/ + /repos/:owner/:repo/commits/:ref/statuses
(not orgs/mydummyorg/ in front of /repos/:owner/:repo/commits/:ref/statuses)
Finally, you need to be registered as the owner or collaborator on that private repo, or even if you do pass your complete credentials (username + password), the answer will always be 404.
Make sure you didn't activate 2FA, or your username+password wouldn't work (you would need to use a PAT -- Personal Access Token -- instead)
The OP Bhavik Shah details in the comments:
I was able to resolve the issue.
The owner detail that I was passing was wrong. It should be organisation name under which the repository is present.

Cannot upload github release asset through API

I have a github release with no assets yet:
$ curl https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets
[
]
But I cannot upload an asset to this release:
$ curl -X POST --header "Content-Type:application/edn" --data-binary #cljsdocs-full.edn "https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets?name=full.edn&access_token=$(cat my-token)"
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
my api access token has public_repo access. Thanks for any helping on uploading this asset.
You're making the POST request to https://api.github.com/repos/cljsinfo/api-docs/releases/1260660/assets which is not the upload URL for the release. It should be https://uploads.github.com/repos/cljsinfo/api-docs/releases/1260660/assets.
See the docs for more info:
https://developer.github.com/v3/repos/releases/#upload-a-release-asset
The asset upload URL is of the form https://<upload_url>/repos/:owner/:repo/releases/:id/assets?name=foo.zip. There are several possible reasons you might get the very unhelpful "Not Found" error:
Wrong release id. The :id field in the URL above is NOT the name you gave the release, but a numeric id generated by GitHub (probably a database ID). To get the release ID, you have to call the releases API and search through the JSON response for a release where the tag_name is equal to the name you used. For example, if you named your release v0.0.3, search in the JSON for a release with "tag_name": "v0.0.3" and use that release's id field.
Wrong upload URL. The URL you use to upload assets is not the same one ou use for all other API calls. To get the right upload URL, you use the same releases API, find your release using tag_name a described above, and extract the upload_url field from the JSON response. This is Ivan's (accepted) answer.
Missing GitHub access token permissions. This is the one that tripped me up the worst, as the token I was using was able to make API calls to the releases API and get info about my repo, but NOT upload assets to that same repo. The "Not Found" error response doesn't hint at this at all. Check the permissions for your token in your personal access tokens page and make sure repo and/or public_repo are checked, as appropriate.
Note that for Enterprise flavored GitHub, the upload url isn't the same form as for 'github.com', and you should use the 'upload_url' returned when creating/querying the release:Get Release API Docs
For example here's what's returned from our enterprise github server (slightly munged to protect the guilty):"upload_url": "https://git.example.com/api/uploads/repos/example-owner/example-repo/releases/5/assets{?name,label}",

LDAP with gitlab: Undefined method persisted

I'm currently setting up a gitlab server using a LDAP backend.
When I try to login as a user present in the LDAP db, I get the following error:
"Could not authorize you from LDAP because: "Undefined method 'persisted?' for #"
Peeking into the source code (specifically app/controllers/omniauth_callbacks_controller.rb) the villain seems to be:
#user = Gitlab::LDAP::User.find_or_create(oauth)
#user.remember_me = true if #user.persisted?
It is totally correct for him to fail here because there is no method persisted? (neither in lib/gitlab/ldap/user.rb nor lib/gitlab/oauth/user.rb). Changing the second line to
#user.remember_me = false #true if #user.persisted?
doesn't work either since remember_me is an invalid function for ruby.
I really have no clue about ruby, let alone Ruby On Rails, so I stopped digging here.
Since I certainly am not the first person to try using LDAP auth in gitlab I consider this an error on my side. Since authentication seems to work (if I enter a false password for the user gitlab happily tells me so), I don't have any idea where to start looking.
I appreciate any help from you guys,
Best Richard
Edit: My gitlab.yml is here.
Solved the problem myself. The database lookup yielded a nil object due to the user creation failing (whenever a ldap user logs in, gitlab uses the ldap data to fill its own database).
During creation of the user database entry the query got an invalid email entry resulting in a failed insert query. Unfortunately this was very hard to debug.
In case anyone should have this problem, try changing the following code in lib/gitlab/oauth/user.rb:
begin
user.save!
rescue ActiveRecord::RecordInvalid => e
raise_error ("(OAuth) Error #{e.to_s}") # <-- add this line
log.info "(OAuth) Email #{e.record.errors[:email]}. Username #{e.record.errors[:username]}"
return nil, e.record.errors
end
This will - in case gitlab is not able to add your user - print the error message the database backend returned as the usual red error banner when trying to log in. Keep in mind to remove this line when you no longer need it.
I can suggest a patch (tested on Gitlab 7.1.0). This code sets the gitlab_rails['ldap_uid'] as username when a ldap user is connecting for the first time :
in /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/oauth/user.rb (see INCLUDE START and STOP) :
user = model.build_user(opts)
user.skip_confirmation!
# Services like twitter and github does not return email via oauth
# In this case we generate temporary email and force user to fill it later
if user.email.blank?
user.generate_tmp_oauth_email
elsif provider != "ldap"
# Google oauth returns email but dont return nickname
# So we use part of email as username for new user
# For LDAP, username is already set to the user's
# uid/userid/sAMAccountName.
email_username = email.match(/^[^#]*/)[0]
# Strip apostrophes since they are disallowed as part of username
user.username = email_username.gsub("'", "")
else
# INCLUDE START
# if LDAP config "ldap_uid" is set : we pick this attribute to set the username :
if ldap_conf['uid'].present?
user.username = auth.extra.raw_info.send(ldap_conf['uid'])[0]
end
# INCLUDE STOP
end
begin
user.save!
In my case the problem was importing (copying file) fro old gitlab repositories to new one.
Gitlab wasn't able to create clean folder for the new user.
Solution:
remove imported repositories
create new, empty repository by first login with LDAP credentials
read your PRIVATE-TOKEN
start gitlab server on your repository ie. 'git daemon --verbose --export-all'
import data from old gitlab using API:
curl -X POST --header "PRIVATE-TOKEN: xxxxxffxxxyyxxxxzzz" http://testserver07.lq/api/v3/projects"?name=project01&import_url=git://localhost/var/opt/gitlab/git-data/repositories-old/repos/project01.git"
First, check if your email address in Gitlab DB is correct:
# login to Gitlab DB (MySql)
mysql -u gitlab gitlabhq_production -p
# check user email address
select email from users where username like 'foo';
Then remove stored LDAP objects from Gitlab DB for the user:
# clear ldap data
update users set extern_uid = '' where username = 'foo';
On next login Gitlab write a new extern_uid.

Resources