From 4f2030ad6c67ee3f113a5eced839fc1a3737a8ce Mon Sep 17 00:00:00 2001 From: Michael Woodworth Date: Wed, 7 Nov 2012 18:15:27 -0500 Subject: [PATCH] added client_id and client_secret auth option --- github/Github.py | 4 ++-- github/Requester.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/github/Github.py b/github/Github.py index 60f8be1f..9bb2cca9 100644 --- a/github/Github.py +++ b/github/Github.py @@ -30,8 +30,8 @@ DEFAULT_TIMEOUT = 10 class Github(object): - def __init__(self, login_or_token=None, password=None, base_url=DEFAULT_BASE_URL, timeout=DEFAULT_TIMEOUT): - self.__requester = Requester(login_or_token, password, base_url, timeout) + def __init__(self, login_or_token=None, password=None, base_url=DEFAULT_BASE_URL, timeout=DEFAULT_TIMEOUT, client_id=None, client_secret=None): + self.__requester = Requester(login_or_token, password, base_url, timeout, client_id, client_secret) @property def FIX_REPO_GET_GIT_REF(self): diff --git a/github/Requester.py b/github/Requester.py index 1f3214f8..2dc08f7b 100644 --- a/github/Requester.py +++ b/github/Requester.py @@ -37,7 +37,7 @@ class Requester: cls.__httpConnectionClass = httpConnectionClass cls.__httpsConnectionClass = httpsConnectionClass - def __init__(self, login_or_token, password, base_url, timeout): + def __init__(self, login_or_token, password, base_url, timeout, client_id=None, client_secret=None): if password is not None: login = login_or_token self.__authorizationHeader = "Basic " + base64.b64encode(login + ":" + password).replace('\n', '') @@ -63,6 +63,9 @@ class Requester: self.rate_limiting = (5000, 5000) self.FIX_REPO_GET_GIT_REF = True + self.__client_id = client_id + self.__client_secret = client_secret + def requestAndCheck(self, verb, url, parameters, input): status, headers, output = self.requestRaw(verb, url, parameters, input) output = self.__structuredFromJson(output) @@ -129,6 +132,14 @@ class Requester: return status, responseHeaders, output def __completeUrl(self, url, parameters): + if self.__client_id and self.__client_secret: + client_parameters = {'client_id': self.__client_id, 'client_secret': self.__client_secret} + if parameters is None or len(parameters) == 0: + return url + '?' + urllib.urlencode(client_parameters) + else: + return url + "?" + urllib.urlencode(parameters) + '&' + urllib.urlencode(client_parameters) + + #there is no client id and secret if parameters is None or len(parameters) == 0: return url else: