hickford / git-credential-oauth

A Git credential helper that securely authenticates to GitHub, GitLab and BitBucket using OAuth.
Apache License 2.0
417 stars 14 forks source link

git fetch from my GitHub repo fails with "remote: Repository not found." despite apparently successful Oauth. #63

Open JDLH opened 1 week ago

JDLH commented 1 week ago

git fetch from my GitHub repo fails with "remote: Repository not found." despite apparently successful Oauth.

How to reproduce

  1. In Terminal, install git-credential-oauth in my git installation on macOS using MacPorts.
  2. Perform % git credential-oauth configure. Successful.
  3. cd to local clone of a GitHub repo.
  4. git fetch. Command prints (line breaks added for legibility):
    https://github.com/login/oauth/authorize?client_id=deadbeef...
    &code_challenge=blah_blah_elided&code_challenge_method=S256
    &redirect_uri=http%3A%2F%2F127.0.0.1%3A53123&response_type=code
    &scope=repo+gist+workflow&state=blah_blah_elided
  5. I am prompted for a GitHub login, and I successfully login. (Or I see a browser tab which says, "Success. You may close this page and return to Git.")

Observed behaviour Command's output continues,

remote: Repository not found.
fatal: repository 'https://github.com/MyUserID/my-repo.git/' not found

Git fetch does not occur.

Expected behaviour No error message. git fetch succeeds.

Discussion The repository URL 'https://github.com/MyUserID/my-repo.git/' appears to be correct. I suspect that the repository is present on the remote, but that authentication was not acceptable to GitHub, and so they tell the command that it is not present.

Setting the helper command to oauth -verbose prints out lines beginning query:, token:, and output:, but does not give any kind of diagnostic reporting a failure.

andreobrown commented 1 week ago

@JDLH I ran into the same issue. Is the repository that you're trying to clone a part of a GitHub Organization? If so, you'll need to follow these instructions to allow OAuth access for git-credentials-oauth: https://github.com/hickford/git-credential-oauth/issues/58#issuecomment-2251548277

JDLH commented 1 week ago

@andreobrown Thank you for the hint! Yes, the repo I am trying to access is related to a GitHub Organization. Specifically, it is my GitHub account's clone of the organisation's repo, and the repo contains a submodule which refers to another of the organisation's repos.

Following the instructions at Requesting organization approval for OAuth apps, in the page for Application git-credential-oauth, under Organization access, I see the name of the owning GitHub Organization, and an "X" implying no access, and a "Request" button which I can push to ask the org to grant me access.

If this turns out to be the underlying cause, then I may propose a Pull Request with an improvement to the git-credential-oauth documentation to cover this situation better.

JDLH commented 1 week ago

I have asked my organisation to approve my use of git-credential-oauth. If/when they grant it, and it works, I intend to report back here.

For what it's worth, I filed a GitHub Docs issue #34710 Clarify use of OAuth credential helpers in local Git installation and Pull Request #34712 Patch for #34710, improving caching credentials with oauth mention. If those get accepted, then that may prevent future occurrences of this issue and #58 appearing in this project's issues list.