Open
Description
Is your feature request related to a problem? Please describe.
Access tokens are not cached for AzureCliCredential
, which adds 3s to every single HTTP request that needs an access token. This quickly adds up and slows down development work.
Describe the solution you'd like
Cache tokens for the duration of their lifetime minus 5 minutes.
Describe alternatives you've considered
A decorator can be used to intercept calls to AzureCliCredential.get_token()
and cache tokens:
import time
import azure.identity
from azure.core.credentials import AccessToken
_access_tokens: dict[tuple[str], AccessToken] = {}
_get_token = azure.identity.AzureCliCredential.get_token
def get_token_decorator(self, *scopes: str, claims: Optional[str] = None, tenant_id: Optional[str] = None, **kwargs: Any) -> AccessToken:
token = _access_tokens.get(scopes, None)
if token is None or int(time.time()) >= token.expires_on - 300:
token = _get_token(self, *scopes, claims = claims, tenant_id = tenant_id, **kwargs)
_access_tokens[scopes] = token
return token
azure.identity.AzureCliCredential.get_token = get_token_decorator
Metadata
Metadata
Assignees
Labels
This issue points to a problem in the data-plane of the library.Issues that are reported by GitHub users external to the Azure organization.Workflow: The Azure SDK team believes it to be addressed and ready to close.The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Type
Projects
Status
Untriaged