Skip to content

Commit b9d0d00

Browse files
committed
Save cookies for re-use when using the last start auth response
1 parent b4cf6b9 commit b9d0d00

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ark_sdk_python/auth/identity/ark_identity.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from cachetools import LRUCache, cached
1717
from pydantic import ValidationError
1818
from requests import Session
19+
from requests.cookies import RequestsCookieJar
1920

2021
from ark_sdk_python.args import ArkArgsFormatter, ArkInquirerRender
2122
from ark_sdk_python.auth.identity.ark_identity_fqdn_resolver import ArkIdentityFQDNResolver
@@ -73,7 +74,7 @@ def input_process(pipe_write: Connection, pipe_read: Connection, mechanism: Mech
7374

7475

7576
class ArkIdentity:
76-
__LAST_START_AUTH_RESP: Dict[str, Tuple[StartAuthResponse, datetime]] = {}
77+
__LAST_START_AUTH_RESP: Dict[str, Tuple[StartAuthResponse, datetime, RequestsCookieJar]] = {}
7778
__LAST_START_AUTH_RESP_DELTA_SECONDS: Final[int] = 30
7879

7980
def __init__(
@@ -478,7 +479,11 @@ def is_password_required(cls, username: str, identity_url: Optional[str], identi
478479
identity_tenant_subdomain=identity_tenant_subdomain,
479480
)
480481
resp = identity.__start_authentication()
481-
ArkIdentity.__LAST_START_AUTH_RESP[f'{identity.identity_url}_{username}'] = (resp, datetime.now())
482+
ArkIdentity.__LAST_START_AUTH_RESP[f'{identity.identity_url}_{username}'] = (
483+
resp,
484+
datetime.now(),
485+
identity.session.cookies,
486+
)
482487
return (
483488
resp.result.idp_redirect_url == None
484489
and resp.result.challenges
@@ -533,6 +538,7 @@ def auth_identity(self, profile: Optional[ArkProfile] = None, interactive: bool
533538
start_auth_response_time = ArkIdentity.__LAST_START_AUTH_RESP[f'{self.__identity_url}_{self.__username}']
534539
if (datetime.now() - start_auth_response_time[1]).total_seconds() < ArkIdentity.__LAST_START_AUTH_RESP_DELTA_SECONDS:
535540
start_auth_response = start_auth_response_time[0]
541+
self.__session.cookies.update(start_auth_response_time[2])
536542
del ArkIdentity.__LAST_START_AUTH_RESP[f'{self.__identity_url}_{self.__username}']
537543
if not start_auth_response:
538544
start_auth_response = self.__start_authentication()

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ark-sdk-python"
3-
version = "2.0.3"
3+
version = "2.0.4"
44
description='Official Ark SDK / CLI for CyberArk Identity Security Platform'
55
authors = ["CyberArk <[email protected]>", "Ofir Iluz <[email protected]"]
66
readme = "README.md"

0 commit comments

Comments
 (0)