Skip to content

Commit 988ddde

Browse files
committed
Add support for Github's OAuth authentication URLs.
When using OAuth instead of api_token authentication, these URL's don't POST username+api_token, but add a ?access_token= query parameter to the calls.
1 parent 2445800 commit 988ddde

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

github2/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Github(object):
88

99
def __init__(self, username=None, api_token=None, debug=False,
10-
requests_per_second=None):
10+
requests_per_second=None, access_token=None):
1111
"""
1212
An interface to GitHub's API:
1313
http://develop.github.com/
@@ -17,6 +17,10 @@ def __init__(self, username=None, api_token=None, debug=False,
1717
1818
`api_token` can be found here (while logged in as that user):
1919
https://github.com/account
20+
21+
`access_token` can be used when no ``username`` and/or ``api_token``
22+
is used. The ``access_token`` is the OAuth access token that is
23+
received after successful OAuth authentication.
2024
2125
`requests_per_second` is a float indicating the API rate limit
2226
you're operating under (1 per second per GitHub at the moment),
@@ -28,7 +32,8 @@ def __init__(self, username=None, api_token=None, debug=False,
2832
self.debug = debug
2933
self.request = GithubRequest(username=username, api_token=api_token,
3034
debug=self.debug,
31-
requests_per_second=requests_per_second)
35+
requests_per_second=requests_per_second,
36+
access_token=access_token)
3237
self.issues = Issues(self.request)
3338
self.users = Users(self.request)
3439
self.repos = Repositories(self.request)

github2/request.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ class GithubRequest(object):
3131
}
3232

3333
def __init__(self, username=None, api_token=None, url_prefix=None,
34-
debug=False, requests_per_second=None):
34+
debug=False, requests_per_second=None, access_token=None):
3535
"""
3636
Make an API request.
3737
"""
3838
self.username = username
3939
self.api_token = api_token
40+
self.access_token = access_token
4041
self.url_prefix = url_prefix
4142
self.debug = debug
4243
if requests_per_second is None:
@@ -52,7 +53,9 @@ def __init__(self, username=None, api_token=None, url_prefix=None,
5253
}
5354

5455
def encode_authentication_data(self, extra_post_data):
55-
if self.username and self.api_token:
56+
if self.access_token:
57+
post_data = {"access_token": self.access_token}
58+
elif self.username and self.api_token:
5659
post_data = {"login": self.username,
5760
"token": self.api_token}
5861
else:

0 commit comments

Comments
 (0)