Skip to content

Instantly share code, notes, and snippets.

@vivekseth
Forked from anonymous/github-oauth.py
Created December 25, 2015 20:25
Show Gist options
  • Save vivekseth/5d80a7f24f73464a9b03 to your computer and use it in GitHub Desktop.
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.
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