I finally managed to find a solution.
class SimpleTokenCredential(TokenCredential):
"""Implements a simple token credential for use with Azure SDK clients."""
def __init__(self, token, expires_on):
self.token = token
if isinstance(expires_on, str):
self.expires_on = (
datetime.fromisoformat(expires_on.rstrip("Z"))
.replace(tzinfo=pytz.utc)
.timestamp()
)
def get_token(self, *scopes, **kwargs):
# Assuming that 'expires_on' is a datetime object representing the expiration time
expiration_epoch = int(self.expires_on)
return AccessToken(self.token, expiration_epoch)