A cloud-based identity and access management service for securing user authentication and resource access
Rushi Satani The 403 error is occurring because the access token generated by the Managed Identity does not contain the required application role for the Defender API.
The error message clearly states:
Missing application roles. API required roles: Ti.ReadWrite.All, Ti.ReadWrite
This means authentication is successful, but authorization is failing.
When using Managed Identity, the Defender API requires Application permissions (not delegated permissions). If the required role is not assigned to the service principal, the API returns 403 even though the token is valid.
Assign Required Application Permission
- Go to Microsoft Entra ID
- Navigate to Enterprise Applications
- Search for your Azure Function’s Managed Identity
- Go to Permissions
- Click Add permission
- Select Microsoft Defender for Endpoint
- Choose Application permissions
- Add one of the following:
-
Ti.ReadWrite - or
Ti.ReadWrite.All
-
Grant Admin Consent
After adding the permission, click:
Grant admin consent
This step is mandatory. Without admin consent, the role will not be included in the issued token.
Use Correct Scope When Requesting Token
Ensure the token is requested with:
https://api.security.microsoft.com/.default
Example:
new TokenRequestContext(new[] { "https://api.security.microsoft.com/.default" })
Verify the Token
Decode the newly generated token (for example using jwt.ms) and confirm:
aud = https://api.security.microsoft.com
roles claim contains:
"Ti.ReadWrite"
or
"Ti.ReadWrite.All"
If the roles claim is missing, the permission was not properly assigned or consented.