Skip to content

Instantly share code, notes, and snippets.

Created December 25, 2015 20:24
Show Gist options
  • Save anonymous/2cf26f4251272942f853 to your computer and use it in GitHub Desktop.
Save anonymous/2cf26f4251272942f853 to your computer and use it in GitHub Desktop.
This python script outputs an OAuth Authorization token for use with Github's API. Username and password are inputted via STDIN, and the authorization token is outputted on STDOUT.
import requests
import base64
import json
import random
import string
username = raw_input()
password = raw_input()
fingerprint = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
headers = {'Authorization': 'Basic ' + base64.b64encode(username + ':' + password)}
data = {"scopes": ["public_repo"],"note": "admin script", "fingerprint": fingerprint}
url = 'https://api.github.com/authorizations'
r = requests.post(url, data=json.dumps(data), headers=headers)
print r.json()['token']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment