##// END OF EJS Templates
PR tester can now post results to Github as a comment.
PR tester can now post results to Github as a comment.

File last commit:

r6694:6ceb0bb2
r6694:6ceb0bb2
Show More
gh_auth.py
42 lines | 1.1 KiB | text/x-python | PythonLexer
"""Functions for Github authorisation."""
from __future__ import print_function
try:
input = raw_input
except NameError:
pass
import requests
import keyring
import getpass
import json
# Keyring stores passwords by a 'username', but we're not storing a username and
# password
fake_username = 'ipython_tools'
def get_auth_token():
token = keyring.get_password('github', fake_username)
if token is not None:
return token
print("Please enter your github username and password. These are not "
"stored, only used to get an oAuth token. You can revoke this at "
"any time on Github.")
user = input("Username: ")
pw = getpass.getpass("Password: ")
auth_request = {
"scopes": [
"public_repo"
],
"note": "IPython tools"
}
response = requests.post('https://api.github.com/authorizations',
auth=(user, pw), data=json.dumps(auth_request))
response.raise_for_status()
token = json.loads(response.text)['token']
keyring.set_password('github', fake_username, token)
return token