Skip to content

Commit 0cb8f73

Browse files
committed
Bearer token support (using Splunk Token presented in v7.3)
1 parent cd268aa commit 0cb8f73

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

splunklib/binding.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def __init__(self, handler=None, **kwargs):
481481
self.username = kwargs.get("username", "")
482482
self.password = kwargs.get("password", "")
483483
self.basic = kwargs.get("basic", False)
484+
self.bearerToken = kwargs.get("splunkToken", "")
484485
self.autologin = kwargs.get("autologin", False)
485486
self.additional_headers = kwargs.get("headers", [])
486487

@@ -521,6 +522,9 @@ def _auth_headers(self):
521522
elif self.basic and (self.username and self.password):
522523
token = 'Basic %s' % b64encode(("%s:%s" % (self.username, self.password)).encode('utf-8')).decode('ascii')
523524
return [("Authorization", token)]
525+
elif self.bearerToken:
526+
token = 'Bearer %s' % self.bearerToken
527+
return [("Authorization", token)]
524528
elif self.token is _NoAuthenticationToken:
525529
return []
526530
else:
@@ -863,6 +867,10 @@ def login(self):
863867
# as credentials were passed in.
864868
return
865869

870+
if self.bearerToken:
871+
# Bearer auth mode requested, so this method is a nop as long
872+
# as authentication token was passed in.
873+
return
866874
# Only try to get a token and updated cookie if username & password are specified
867875
try:
868876
response = self.http.post(

0 commit comments

Comments
 (0)