mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 19:31:10 +00:00
added client_id and client_secret auth option
This commit is contained in:
+2
-2
@@ -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):
|
||||
|
||||
+12
-1
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user