11"""Module containing session handle classes.
22
33"""
4+ from datetime import datetime , timezone
45import logging
56
67from symphony .bdk .core .auth .exception import AuthInitializationError
78
89logger = logging .getLogger (__name__ )
910
11+ EXPIRATION_SAFETY_BUFFER_SECONDS = 5
12+
1013
1114class AuthSession :
1215 """RSA Authentication session handle to get session and key manager tokens from.
@@ -21,7 +24,9 @@ def __init__(self, authenticator):
2124 """
2225 self ._session_token = None
2326 self ._key_manager_token = None
27+ self ._auth_token = None
2428 self ._authenticator = authenticator
29+ self ._expire_at = - 1
2530
2631 async def refresh (self ):
2732 """Trigger re-authentication to refresh the tokens.
@@ -40,6 +45,26 @@ async def session_token(self):
4045 self ._session_token = await self ._authenticator .retrieve_session_token ()
4146 return self ._session_token
4247
48+ @property
49+ async def auth_token (self ):
50+ """Auth token request calls the same endpoint that session token.
51+ Therefore, session token is updated unintentionally,
52+ since there's no explicit way to update authorization token exclusively
53+ : return: (str) authorization_token like Bearer eyJh...
54+ """
55+
56+ if (
57+ self ._auth_token
58+ and self ._expire_at
59+ > datetime .now (timezone .utc ).timestamp () + EXPIRATION_SAFETY_BUFFER_SECONDS
60+ ):
61+ return self ._auth_token
62+ token , expire_at = await self ._authenticator .retrieve_session_token_object ()
63+ self ._expire_at = expire_at
64+ self ._auth_token = token .authorization_token
65+ self ._session_token = token .token
66+ return self ._auth_token
67+
4368 @property
4469 async def key_manager_token (self ):
4570 """
0 commit comments