An Azure service that provides an event-driven serverless compute platform.
Hello Jesper Vest Hansen,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are having federated Credentials for Defender API issue.
Because, the cross‑tenant “workload identity federation” using a Managed Identity fails unless the target app is explicitly trusted and provisioned in that tenant, and the FIC uses the exact audience api://AzureADTokenExchange; otherwise the remote tenant won’t accept the token (multi‑tenant trust is not implicit) (see FIC overview and Configure an app to trust a managed identity prerequisites/restrictions (same‑tenant or multi‑tenant + provisioning). - https://learn.microsoft.com/en-us/graph/api/resources/federatedidentitycredentials-overview?view=graph-rest-1.0
The symptom (unsupported flow) shows that ManagedIdentity > token exchange > remote tenant ⇒ 401/invalid_token.
To resolve this, follow the below steps:
- Use the supported app‑only pattern (most recommended): Register an app, grant Defender API Application permissions, and authenticate with client secret or certificate; then request a token for
https://api.security.microsoft.com/.defaultand call the Defender API (official MDE/XDR guides). - https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation-config-app-trust-managed-identity, https://learn.microsoft.com/en-us/defender-endpoint/api/exposed-apis-create-app-webapp# OAuth2 v2.0 (client credentials) curl -s -X POST https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token </span> -d 'grant_type=client_credentials&client_id=<appId>&client_secret=<secret>'</span> -d 'scope=https://api.security.microsoft.com/.default' - Make it multi‑tenant and consent in the customer tenant by setting the app to multi‑tenant, then have an admin in the remote tenant grant consent to the requested app roles (tenant‑wide admin consent flow). - https://learn.microsoft.com/en-us/defender-xdr/api-create-app-web, https://learn.microsoft.com/en-us/defender-xdr/api-create-app-web
# Admin consent URL the customer executes https://login.microsoftonline.com/<remoteTenant>/adminconsent?client_id=<appId> - Only if you MUST use Federation keep it single‑tenant (same tenant for MI and app) and configure the FIC precisely with issuer/subject matching your Managed Identity and audience set to
api://AzureADTokenExchange(case‑sensitive). - https://learn.microsoft.com/en-us/graph/api/resources/federatedidentitycredentials-overview?view=graph-rest-1.0, https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/grant-admin-consent -
{ "issuer":"https://login.microsoftonline.com/<tenant>/v2.0", "subject":"<managed-identity-object-id>", "audiences":["api://AzureADTokenExchange"] } - Then, use the app’s token to call Defender XDR or Defender for Endpoint APIs over
api.security.microsoft.com(or geo‑specific hosts) as documented. - https://learn.microsoft.com/en-us/defender-endpoint/api/exposed-apis-create-app-webapp, https://learn.microsoft.com/en-us/defender-endpoint/api/exposed-apis-create-app-nativeappcurl -H "Authorization: Bearer $ACCESS_TOKEN" </span> https://api.security.microsoft.com/api/incidents - For cross‑tenant Defender API access, prefer certificate‑based client‑credential over secrets, and avoid MI‑based federation for this scenario; Microsoft explicitly recommends certificates for production app credentials. - https://learn.microsoft.com/en-us/defender-endpoint/api/exposed-apis-create-app-webapp, https://learn.microsoft.com/en-us/entra/identity-platform/how-to-add-credentials
# Upload cert to the app, then authenticate with client assertion (JWT) # (per Entra “Add and manage application credentials” guidance)
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.