Created
January 25, 2017 16:31
-
-
Save sportebois/800bd11be9fb8a214f3a05bd3e973b47 to your computer and use it in GitHub Desktop.
Get OAUth token for Github
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
#!/usr/bin/env python | |
import requests | |
import argparse | |
parser = argparse.ArgumentParser(description='Generate a Github OAuth token.') | |
parser.add_argument('--user', metavar='u', dest='user', required=True, help='Github username') | |
parser.add_argument('--password', dest='password', required=True, help='Github password') | |
parser.add_argument('--2fa', dest='mfaToken', required=True, help='Github 2FA code') | |
args = parser.parse_args() | |
params = dict( | |
note = 'Purpose of the token', | |
scopes = ['repo', 'read:org'] | |
) | |
headers = {'X-GitHub-OTP': args.mfaToken} | |
resp = requests.post('https://api.github.com/authorizations', params=params, auth=(args.user, args.password), headers=headers) | |
data = resp.text | |
print data | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment