Login with GitHub Personal Access Token (PAT)
For situations where it is difficult or impossible to login with a username and password, there is an alternative way to login with a GitHub PAT. To utilize this functionality:
Note: the same restrictions apply to users regardless of login method (i.e. you do not gain additional permissions by logging in with a token).
Create a GitHub PAT with at least the
read:user,read:org, andreposcopes.Make a request to
/api/auth/token-loginwith an additional header:Authorization: Bearer <your-token>Get the session cookie from the
set-cookieheader in the response.Make additional response with the session cookie.
Example
import os
import requests
# Note: This example assumes you are running CORGI locally
my_token = os.environ["TOKEN"] # Don't hardcode secrets ;)
with requests.session() as session:
response = session.get(
"http://localhost/api/auth/token-login",
headers={"Authorization": f"Bearer {my_token}"})
assert response.cookies.get("session", None) is not None, \
"Could not get session cookie"
# Now your cookie will be used to make requests that require a valid user
# session
jobs = session.get("http://localhost/api/jobs")
print(jobs.json())