-
-
Save vivekseth/5d80a7f24f73464a9b03 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