Skip to content

Commit fa2de94

Browse files
committed
Fix refresh token bug
1 parent e899aaf commit fa2de94

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

splunk_sdk/auth/auth_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ def authenticate(self):
443443
"client_id": client_id,
444444
"grant_type": "refresh_token",
445445
"refresh_token": self._refresh_token,
446-
"scope": self._scope}
447-
response = self._post_token(data)
446+
"scope": self._scope
447+
}
448+
449+
response = self._post_token(**data)
448450
return AuthContext(**response.json())

test/auth/test_auth_manager.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from splunk_sdk import Context
66
from splunk_sdk.auth import TokenAuthManager
7-
from splunk_sdk.auth.auth_manager import AuthnError
7+
from splunk_sdk.auth.auth_manager import AuthnError, RefreshTokenAuthManager
88
from splunk_sdk.base_client import BaseClient
99
from splunk_sdk.identity import Identity as IdentityAndAccessControl
1010
from splunk_sdk.auth import PKCEAuthManager, ClientAuthManager
@@ -34,6 +34,31 @@ def test_auth_error_properties(pkce_auth_manager):
3434
finally:
3535
pkce_auth_manager._password = save_passwd
3636

37+
@pytest.mark.usefixtures('pkce_auth_manager') # NOQA
38+
def test_refresh_token_authenticate(pkce_auth_manager):
39+
auth_context = pkce_auth_manager.authenticate()
40+
41+
# use existing token from auth_context
42+
refresh_token_mgr = RefreshTokenAuthManager(client_id=os.environ.get('SPLUNK_APP_CLIENT_ID'),
43+
refresh_token=auth_context.refresh_token,
44+
host=os.environ.get('SPLUNK_AUTH_HOST'))
45+
46+
new_auth_context = refresh_token_mgr.authenticate()
47+
48+
assert (new_auth_context.refresh_token is not None)
49+
assert (new_auth_context.access_token is not None)
50+
assert (new_auth_context.id_token is not None)
51+
assert (new_auth_context.token_type is not None)
52+
assert (new_auth_context.expires_in is not None)
53+
assert (new_auth_context.scope is not None)
54+
55+
def test_error_refresh_token_authenticate():
56+
refresh_token_mgr = RefreshTokenAuthManager(client_id=os.environ.get('SPLUNK_APP_CLIENT_ID'),
57+
refresh_token="refresh",
58+
host=os.environ.get('SPLUNK_AUTH_HOST'))
59+
60+
with pytest.raises(AuthnError):
61+
refresh_token_mgr.authenticate()
3762

3863
@pytest.mark.usefixtures('client_auth_manager') # NOQA
3964
def test_client_credentials_authenticate(client_auth_manager):

0 commit comments

Comments
 (0)