Skip to content

Instantly share code, notes, and snippets.

@pelson
Last active February 21, 2024 16:05
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save pelson/47c0c89a3522ed8da5cc305afc2562b0 to your computer and use it in GitHub Desktop.
Save pelson/47c0c89a3522ed8da5cc305afc2562b0 to your computer and use it in GitHub Desktop.
Example of authenticating a GitHub app using jwt in Python
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@OrkoHunter
Copy link

Thank you very much!

@mjparangot
Copy link

Thank you, this helps a lot!

@Hefeweizen
Copy link

Thanks for this, I found it very helpful.

Two notes that I also found helpful:

@SijmenHuizenga
Copy link

Thank you so much!

@saisankargochhayat
Copy link

Thank you this helps a lot.

@brechtm
Copy link

brechtm commented Apr 20, 2020

Note that this functionality is offered by github3.py. See Issue with JWT token authentication in PyGithub for an example. The access token can be retrieved from the GitHub instance (GitHub.session.auth.token).

@dorneanu
Copy link

Thanks for this!

@hkhrais
Copy link

hkhrais commented Feb 18, 2021

Thanks for this!

@Grimulus
Copy link

Grimulus commented Oct 1, 2021

Really appreciate this, it was super helpful!

@samit2040
Copy link

Awesomely explained !!
In [53] code block
headers = {"Authorization": "Bearer {}".format(actual_jwt.decode()) ....
will be
headers = {"Authorization": "Bearer {}".format(actual_jwt) .....

@santos-edu
Copy link

@samit2040 its right
@pelson tks!!!

@santos-edu
Copy link

In [60] code block
resp = requests.post('https://api.github.com/installations/{}/access_tokens'.format(installation_id),
will be
resp = requests.post('https://api.github.com/app/installations/{}/access_tokens'.format(installation_id),

@briansizemore37
Copy link

This was super helpful. Thank you so much!

@toderesa97
Copy link

Just in case is wondering, these are the dependencies needed. Do not install jwt but pyjwt. (see https://stackoverflow.com/questions/33198428/jwt-module-object-has-no-attribute-encode).

certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
cryptography==38.0.3
idna==3.4
pycparser==2.21
PyJWT==2.6.0
requests==2.28.1
urllib3==1.26.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment