forked from codeafrica/github-africa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
executable file
·43 lines (33 loc) · 1.08 KB
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ai ts=4 sts=4 et sw=4 nu
from __future__ import (unicode_literals, absolute_import,
division, print_function)
import logging
import json
import requests
from requests.auth import HTTPBasicAuth
from secret import CLIENT_ID, CLIENT_SECRET, GITHUB_USERNAME, GITHUB_PASSWORD, GITHUB_OTP
logger = logging.getLogger(__name__)
payload = {
"scopes": [
"public_repo"
],
"note": "codeafrica script",
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET
}
headers = {"X-GitHub-OTP": GITHUB_OTP}
req = requests.post("https://api.github.com/authorizations",
data=json.dumps(payload),
auth=HTTPBasicAuth(GITHUB_USERNAME, GITHUB_PASSWORD),
headers=headers)
from pprint import pprint as pp ; pp(req.headers)
try:
resp = json.loads(req.text)
except:
resp = req.text
from pprint import pprint as pp ; pp(resp)
if 'token' in resp:
print("!!! Run the following in your shell:")
print('export GITHUB_TOKEN="{}"'.format(resp['token']))