Skip to content

Commit

Permalink
Merge pull request #463 from splunk/preserve_thirdparty_cookies
Browse files Browse the repository at this point in the history
Preserve thirdparty cookies
  • Loading branch information
fantavlik committed Jun 13, 2022
2 parents 31cf507 + 9dbc86b commit 27f8fbf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions splunklib/binding.py
Expand Up @@ -526,23 +526,27 @@ def _auth_headers(self):
:returns: A list of 2-tuples containing key and value
"""
header = []
if self.has_cookies():
return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))]
elif self.basic and (self.username and self.password):
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
return [("Authorization", token)]
elif self.bearerToken:
token = 'Bearer %s' % self.bearerToken
return [("Authorization", token)]
elif self.token is _NoAuthenticationToken:
return []
token = []
else:
# Ensure the token is properly formatted
if self.token.startswith('Splunk '):
token = self.token
else:
token = 'Splunk %s' % self.token
return [("Authorization", token)]
if token:
header.append(("Authorization", token))
if self.get_cookies().__len__() > 0:
header.append("Cookie", _make_cookie_header(self.get_cookies().items()))

return header

def connect(self):
"""Returns an open connection (socket) to the Splunk instance.
Expand Down

0 comments on commit 27f8fbf

Please sign in to comment.