We’ve been maintaining a custom agent desktop widget using the Genesys Cloud Python SDK for about two years now. The setup has been stable, but we noticed some agents getting logged out unexpectedly during long shifts. I dug into the code and realized we’ve been manually handling token refreshes.
The current implementation uses a background thread to check the token expiry every 5 minutes. If it’s close to expiring, it calls the refresh endpoint directly. It works, but it’s clunky. The SDK docs mention that AuthClient should handle this automatically if configured correctly.
Here is how we are initializing the client:
from gen_cloud_python_sdk.gen_cloud_python_sdk_client import ApiClient
from gen_cloud_python_sdk.auth import AuthClient
auth_client = AuthClient(
client_id='our_client_id',
client_secret='our_client_secret',
api_base_uri='https://api.mypurecloud.com'
)
# We explicitly call this every 60 minutes in a loop
# auth_client.refresh_access_token()
I removed the manual refresh loop to test the automatic handling. I set the access_token and refresh_token manually after the initial login for testing purposes. The AuthClient has a get_access_token() method. I assumed it would check the expiry internally.
When the token expires, get_access_token() just returns the expired token. It doesn’t throw an error. It doesn’t refresh. I have to catch the 401 from the API call and then manually trigger a refresh.
Is there a specific flag or method on AuthClient that enables auto-refresh? Or is the Python SDK just not as smart as the JS one? I’ve looked at the source code on GitHub but the logic for AuthClient is buried deep in the base classes.
I want to avoid the complexity of maintaining that background thread if the SDK can do it. Any pointers on how to force the SDK to manage the lifecycle without manual intervention?