Feature Proposal: Built-in Access Token Lifecycle Management
Hi maintainers,
First, thank you for providing and maintaining the Python SDK.
While integrating Kopo Kopo into a Django application [and other frameworks too ], I noticed that the SDK currently provides the primitives necessary to obtain and inspect access tokens through TokenService, but token lifecycle management is left entirely to SDK consumers.
Current Implementation
The relevant functionality is implemented in:
k2connect/token_service.py
Specifically:
request_access_token()
request_token_info()
introspect_access_token()
revoke_access_token()
The authorization documentation states:
- Access tokens are valid for 1 hour (
expires_in)
- Only one access token is valid at a time
As a result, applications need to:
- Request an access token
- Store it
- Track its expiration
- Re-acquire a new token before expiration
- Avoid unnecessary token requests
Real-World Experience
In a production integration, I found myself implementing additional logic outside the SDK to:
- Cache the current token
- Track expiration using
expires_in
- Prevent duplicate token requests
- Automatically obtain a new token when required
This functionality seems likely to be reimplemented by most SDK users.
Proposed Enhancement
Introduce an optional helper method that transparently manages token validity.
Example:
token_service = k2connect.Tokens
access_token = token_service.get_valid_token()
Possible behavior:
- Return cached token if still valid
- Request a new token when expired (or close to expiry)
- Cache token metadata internally
- Remain fully backward compatible with existing APIs
Pseudo implementation:
def get_valid_token(self):
if self._token and not self._is_expired():
return self._token
response = self.request_access_token()
self._token = response["access_token"]
self._expires_at = (
current_time + response["expires_in"]
)
return self._token
##it will be helpful in
- Reducing duplicated authentication code across applications
- Reducing unnecessary authorization requests
- Improving developer experience
- Keeps existing SDK interfaces unchanged and
- Provides a more production-ready authentication workflow
Feature Proposal: Built-in Access Token Lifecycle Management
Hi maintainers,
First, thank you for providing and maintaining the Python SDK.
While integrating Kopo Kopo into a Django application [and other frameworks too ], I noticed that the SDK currently provides the primitives necessary to obtain and inspect access tokens through
TokenService, but token lifecycle management is left entirely to SDK consumers.Current Implementation
The relevant functionality is implemented in:
k2connect/token_service.pySpecifically:
request_access_token()request_token_info()introspect_access_token()revoke_access_token()The authorization documentation states:
expires_in)As a result, applications need to:
Real-World Experience
In a production integration, I found myself implementing additional logic outside the SDK to:
expires_inThis functionality seems likely to be reimplemented by most SDK users.
Proposed Enhancement
Introduce an optional helper method that transparently manages token validity.
Example:
Possible behavior:
Pseudo implementation:
##it will be helpful in