Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting example results in 404, should specify JWT to make it work #147

Open
grjzwaan opened this issue Sep 1, 2022 · 0 comments
Open

Comments

@grjzwaan
Copy link

grjzwaan commented Sep 1, 2022

The simple example results in a 404 error:

api = GhApi(owner='owner', repo='repo', token='<YOUR-TOKEN>')
pulls = api.pulls.list()

but with curl it works (from GitHub docs):

curl \
  -H "Accept: application/vnd.github+json" \ 
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  https://api.github.com/repos/OWNER/REPO/pulls

The following works:

api = GhApi(owner='owner', repo='repo', jwt_token='<YOUR-TOKEN>')
pulls = api.pulls.list()

The personal access token has scopes for repo, workflow, gist and notifications.

Cause

It seems the API call to GitHub expects a different header. The example on GhApi sets Authorization: token <YOUR-TOKEN> but the example on GitHub specifies Authorization: Bearer <YOUR-TOKEN>. On https://docs.github.com/en/rest/overview/other-authentication-methods this is expanded upon with the note:

Note: In most cases, you can use Authorization: Bearer or Authorization: token to pass a token. However, if you are passing a JSON web token (JWT), you must use Authorization: Bearer.

Reading the docs I assume the header Authorization: token <TOKEN> is fine, but the above experimentation indicates otherwise.

Conclusion

I have no clue why 'my' token is regarded as a JWT token here, and in the example of GhApi not. For me it works, but I couldn't find a reason. Perhaps it helps someone searching for this, but I'm also interested to known if it is a setting or ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant