()
| 32 | |
| 33 | token = None |
| 34 | def get_auth_token(): |
| 35 | global token |
| 36 | |
| 37 | if token is not None: |
| 38 | return token |
| 39 | |
| 40 | try: |
| 41 | with open(os.path.join(os.path.expanduser('~'), '.ghoauth')) as f: |
| 42 | token, = f |
| 43 | return token |
| 44 | except Exception: |
| 45 | pass |
| 46 | |
| 47 | import keyring |
| 48 | token = keyring.get_password('github', fake_username) |
| 49 | if token is not None: |
| 50 | return token |
| 51 | |
| 52 | print("Please enter your github username and password. These are not " |
| 53 | "stored, only used to get an oAuth token. You can revoke this at " |
| 54 | "any time on GitHub.") |
| 55 | user = input("Username: ") |
| 56 | pw = getpass.getpass("Password: ") |
| 57 | |
| 58 | auth_request = { |
| 59 | "scopes": [ |
| 60 | "public_repo", |
| 61 | "gist" |
| 62 | ], |
| 63 | "note": "IPython tools", |
| 64 | "note_url": "https://github.com/ipython/ipython/tree/master/tools", |
| 65 | } |
| 66 | response = requests.post('https://api.github.com/authorizations', |
| 67 | auth=(user, pw), data=json.dumps(auth_request)) |
| 68 | response.raise_for_status() |
| 69 | token = json.loads(response.text)['token'] |
| 70 | keyring.set_password('github', fake_username, token) |
| 71 | return token |
| 72 | |
| 73 | def make_auth_header(): |
| 74 | return {'Authorization': 'token ' + get_auth_token().replace("\n","")} |
no test coverage detected
searching dependent graphs…