Skip to content

Fix oauth #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def set_token(self, token=None, oauth_token=None):

if oauth_token:
self.headers.pop("PRIVATE-TOKEN", None)
self.headers["Authorization"] = "Bearer: %s" % oauth_token
self.headers["Authorization"] = "Bearer %s" % oauth_token
elif token:
self.headers.pop("Authorization", None)
self.headers["PRIVATE-TOKEN"] = token
Expand Down Expand Up @@ -397,16 +397,21 @@ def _raw_get(self, path_, content_type=None, streamed=False, **kwargs):
url = '%s%s' % (self._url, path_)

headers = self._create_headers(content_type)
auth = requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password)

if headers["Authorization"]:
auth = None

try:
return self.session.get(url,
params=kwargs,
headers=headers,
verify=self.ssl_verify,
timeout=self.timeout,
stream=streamed,
auth=requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password))
auth=auth)
except Exception as e:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)
Expand Down Expand Up @@ -447,47 +452,60 @@ def _raw_list(self, path_, cls, extra_attrs={}, **kwargs):
def _raw_post(self, path_, data=None, content_type=None, **kwargs):
url = '%s%s' % (self._url, path_)
headers = self._create_headers(content_type)
auth = requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password)

if headers["Authorization"]:
auth = None

try:
return self.session.post(url, params=kwargs, data=data,
headers=headers,
verify=self.ssl_verify,
timeout=self.timeout,
auth=requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password))
auth=auth)
except Exception as e:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)

def _raw_put(self, path_, data=None, content_type=None, **kwargs):
url = '%s%s' % (self._url, path_)
headers = self._create_headers(content_type)
auth = requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password)

if headers["Authorization"]:
auth = None

try:
return self.session.put(url, data=data, params=kwargs,
headers=headers,
verify=self.ssl_verify,
timeout=self.timeout,
auth=requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password))
auth=auth)
except Exception as e:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)

def _raw_delete(self, path_, content_type=None, **kwargs):
url = '%s%s' % (self._url, path_)
headers = self._create_headers(content_type)
auth = requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password)

if headers["Authorization"]:
auth = None

try:
return self.session.delete(url,
params=kwargs,
headers=headers,
verify=self.ssl_verify,
timeout=self.timeout,
auth=requests.auth.HTTPBasicAuth(
self.http_username,
self.http_password))
auth=auth)
except Exception as e:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)
Expand Down