pip install redis-entraid
First you have to configure IdentityProvider, for this purpose there's 2 factory methods:
def create_provider_from_managed_identity(
identity_type: ManagedIdentityType,
resource: str,
id_type: Optional[ManagedIdentityIdType] = None,
id_value: Optional[str] = '',
**kwargs
) -> EntraIDIdentityProvider
def create_provider_from_service_principal(
client_credential,
client_id: str,
scopes: list = [],
timeout: Optional[float] = None,
token_kwargs: dict = {},
**app_kwargs
) -> EntraIDIdentityProvider
This credential provider is running a scheduled background tasks to renew tokens, the specifics might be configured as well:
auth_config = TokenAuthConfig(idp)
cred_provider = EntraIdCredentialsProvider(auth_config)
To obtain token and run background task simply call:
# Sync
cred_provider.get_credentials()
# Async
await cred_provider.get_credentials_async()