I am using azure.identity.aio python SDK to get access_token. For that I use ClientSecretCredential() class. This is current code that I have:
credential = ClientSecretCredential(tenant_id=tenant_id, client_secret=client_secret)
access_token = credential.get_token("{host}/.default".format(host=host))
But I get Confidential Client is not supported in Cross Cloud request error when I set national cloud host such as graph.microsoft.us. I guess, one option is explicitly setting the authority:
credential = ClientSecretCredential(tenant_id=tenant_id, client_secret=client_secret,authority=AzureAuthorityHosts.AZURE_GOVERNMENT)
But what if the login or api host is graph.microsoft.de or graph.microsoft.cn. Is there any way to dynamically set the authority based on the specified hostname?
You can make use of below python code to set authority dynamically based on specified hostname, while requesting token for MS Graph:
Response:
When I decoded the above token in jwt.ms website, I got claims with
audas below: