-
Notifications
You must be signed in to change notification settings - Fork 208
Description
MSAL client type
Public
Problem Statement
We have written a python package (wtwco-igloo on PyPi) that allows our users to use Python to connect to their Igloo Cloud environment that is secured with Entra Id. One form of authentication that we support uses the device code flow to allow the user to interactively supply their user credentials to log in to the Enterprise Application as themselves.
However in order for this to work they need to configure wtwco-igloo to use the correct client_id for their Enterprise Application which causes lots of support issues for us.
It would be much nicer if instead of the user having to find the correct client_id, the wtwco-igloo package could instead use the Application URI of the Enterprise Application which, in our case, is simply the domain name of the URL of the Igloo Cloud API.
This is, for instance, how the Excel OData feature authenticates to our Igloo Cloud environment without requiring the user to know what the client_id is.
The frustrating thing is that this msal package is really close to allowing this feature to work, however there is a check in decode_id_token() that checks that the audience claim in the token retrieved from Entra Id is equal to the client_id passed in to the PublicClientApplication. However this won't be the case when the Application URI is used as the Client Id of the Enterprise Application is returned in the token.
See below for a simple example that I would like to work but which raises the error:
IdTokenAudienceError(
msal.oauth2cli.oidc.IdTokenAudienceError: 3. The aud (audience) claim must contain this client's client_id "https://devcon1.cloud.igloo.wtwsaas.dev", case-sensitively. Was your client_id in wrong casing? Current epoch = 2025-04-11 15:41:46. The id_token was approximately: {
"aud": "f5f74c0d-fdd2-473d-b46d-0066c0ee23a9",
"iss":
...
It might be that you consider this issue to be more of a bug than a feature request, I wasn't too sure.
Many thanks,
Bertie
Proposed solution
I would like the following code to work (you will obviously need to use a different application_uri to match an Enterprise Application that you have access to)
import requests
from msal import PublicClientApplication
application_uri = "https://devcon1.cloud.igloo.wtwsaas.dev"
scope = f"{application_uri}/user_impersonation"
authority = "https://login.microsoftonline.com/organizations"
http_client = requests.Session()
msal_client = PublicClientApplication(client_id=application_uri, authority=authority, http_client=http_client)
flow = msal_client.initiate_device_flow(scopes=[scope])
print(flow["message"])
result = msal_client.acquire_token_by_device_flow(flow)