Skip to content

Instantly share code, notes, and snippets.

@rayne-hernandez
Created May 6, 2024 20:23
Show Gist options
  • Save rayne-hernandez/24a0263f205c2cebede32d998ad4916a to your computer and use it in GitHub Desktop.
Save rayne-hernandez/24a0263f205c2cebede32d998ad4916a to your computer and use it in GitHub Desktop.
OAuth Local Token generation
# Credentials you get from registering a new application
client_id = ""
client_secret = ""
# OAuth endpoints given in the GitHub API documentation
authorization_base_url = ""
token_url = ""
redirect_uri = ""
scope = []
state = "random-string"
from requests_oauthlib import OAuth2Session
client = OAuth2Session(client_id=client_id, scope=scope, redirect_uri=redirect_uri, state=state)
authorization_url, state = client.authorization_url(authorization_base_url)
print(authorization_url, state)
authorization_response = input('Enter the full callback URL: ')
token = client.fetch_token(
token_url,
authorization_response=authorization_response,
client_secret=client_secret
)
print(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment