Skip to content

Instantly share code, notes, and snippets.

@bussiere
Created July 22, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bussiere/ab74419004d93c39c5703e64f82ea1f7 to your computer and use it in GitHub Desktop.
Save bussiere/ab74419004d93c39c5703e64f82ea1f7 to your computer and use it in GitHub Desktop.
Get an Oauth2 token from github with python3
import requests
import json
#r = requests.get('https://composcan-api-dev.herokuapp.com/v1/products', json={"_id": "auth0|5a65b0c09f5e2b5157614782","ea" : "3517360013542"})
#print(r.content)
#print(r.json())
GITHUB_API = 'https://api.github.com'
import requests
import getpass
import json
from urllib.parse import urljoin
def main():
#
# User Input
#
username = 'toto'
password = 'georgesAbitbol'
note = "hou"
#
# Compose Request
#
url = urljoin(GITHUB_API, 'authorizations')
payload = {}
if note:
payload['note'] = note
res = requests.post(
url,
auth = (username, password),
data = json.dumps(payload),
)
#
# Parse Response
#
j = json.loads(res.text)
print(j)
token = j['token']
print('New token: %s' % token)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment