Skip to content

Commit 09d0c0f

Browse files
committed
Updated auth_headers checks
fix for issue 'splunklib expects any Set-Cookie to be an auth cookie from Splunk. This is a problem when authenticating with a bearer token.'
1 parent f5ffb67 commit 09d0c0f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

splunklib/binding.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,23 +518,23 @@ def _auth_headers(self):
518518
519519
:returns: A list of 2-tuples containing key and value
520520
"""
521-
if self.has_cookies():
522-
return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))]
523-
elif self.basic and (self.username and self.password):
524-
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
525-
return [("Authorization", token)]
526-
elif self.bearerToken:
527-
token = 'Bearer %s' % self.bearerToken
528-
return [("Authorization", token)]
529-
elif self.token is _NoAuthenticationToken:
530-
return []
531-
else:
532-
# Ensure the token is properly formatted
521+
if self.token is not _NoAuthenticationToken:
533522
if self.token.startswith('Splunk '):
534523
token = self.token
535524
else:
536525
token = 'Splunk %s' % self.token
537526
return [("Authorization", token)]
527+
elif self.bearerToken:
528+
token = 'Bearer %s' % self.bearerToken
529+
return [("Authorization", token)]
530+
elif self.basic and (self.username and self.password):
531+
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
532+
return [("Authorization", token)]
533+
elif self.has_cookies():
534+
return [("Cookie", _make_cookie_header(list(self.get_cookies().items())))]
535+
else:
536+
# no Authentication token
537+
return []
538538

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

0 commit comments

Comments
 (0)