Skip to content

Commit 0c0f06d

Browse files
committed
avoid sending github auth in deprecated query params
1 parent 25601a3 commit 0c0f06d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

nbviewer/providers/github/client.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,44 @@
2323
class AsyncGitHubClient(object):
2424
"""AsyncHTTPClient wrapper with methods for common requests"""
2525
auth = None
26-
26+
2727
def __init__(self, client=None):
2828
self.client = client or AsyncHTTPClient()
2929
self.github_api_url = os.environ.get('GITHUB_API_URL', 'https://api.github.com/')
3030
self.authenticate()
31-
31+
3232
def authenticate(self):
3333
self.auth = {
3434
'client_id': os.environ.get('GITHUB_OAUTH_KEY', ''),
3535
'client_secret': os.environ.get('GITHUB_OAUTH_SECRET', ''),
36-
'access_token' : os.environ.get('GITHUB_API_TOKEN', ''),
36+
'access_token': os.environ.get('GITHUB_API_TOKEN', ''),
3737
}
38-
self.auth = {k:v for k,v in self.auth.items() if v}
39-
38+
4039
def fetch(self, url, callback=None, params=None, **kwargs):
4140
"""Add GitHub auth to self.client.fetch"""
42-
host = urlparse(url).hostname
43-
4441
if not url.startswith(self.github_api_url):
4542
raise ValueError(
4643
"Only fetch GitHub urls with GitHub auth (%s)" % url
4744
)
4845
params = {} if params is None else params
4946
kwargs.setdefault('user_agent', 'Tornado-Async-GitHub-Client')
50-
if self.auth:
51-
params.update(self.auth)
47+
48+
if self.auth['client_id'] and self.auth['client_secret']:
49+
kwargs['auth_username'] = self.auth['client_id']
50+
kwargs['auth_password'] = self.auth['client_secret']
51+
52+
if self.auth['access_token']:
53+
headers = kwargs.setdefault('headers', {})
54+
headers['Authorization'] = 'token ' + self.auth['access_token']
55+
5256
url = url_concat(url, params)
5357
future = self.client.fetch(url, callback, **kwargs)
5458
future.add_done_callback(self._log_rate_limit)
5559
return future
56-
60+
5761
def _log_rate_limit(self, future):
5862
"""log GitHub rate limit headers
59-
63+
6064
- error if 0 remaining
6165
- warn if 10% or less remain
6266
- debug otherwise

0 commit comments

Comments
 (0)