Created
December 25, 2015 20:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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