Closed
Description
Hello,
I try to make asynchronous calls to the Microsoft Graph API using httpx.AsyncClient
. For authentication I use the azure-identity
package that provides several client classes to easily get an access token:
from azure.identity.aio import EnvironmentCredential
async with EnvironmentCredential() as credential:
token = await credential.get_token(*scopes)
I'd like then to subclass httpx.Auth
and implement the auth_flow
method
class AzureAuth(Auth):
async def auth_flow(self, request):
token = await self._credential.get_token(*self._scopes) # Get the access token or retrieve it from cache
request.headers["Authorization"] = "Bearer " + token.token
yield request
so that I can do things like
async with AsyncClient(base_url="https://graph.microsoft.com", auth=AzureAuth(...)) as client:
response = await client.get("/groups")
The problem is that httpx.Auth.auth_flow
is synchronous. How can I make it asynchronous ?