Share via

Getting 403 for token generated by Managed Identity

Rushi Satani 0 Reputation points
2026-02-18T19:04:26.1766667+00:00

I am trying to call Defender API : https://learn.microsoft.com/en-us/defender-endpoint/api/import-ti-indicators by using managed identity from an azure function.

I am successfully able to generate the token. However the token that is generated keeps giving 403 error.
User's image

I have also turned on system assigned managed identity from the function app

Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

1 answer

Sort by: Most helpful
  1. VEMULA SRISAI 9,255 Reputation points Microsoft External Staff Moderator
    2026-02-18T21:05:52.9766667+00:00

    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

    1. Go to Microsoft Entra ID
    2. Navigate to Enterprise Applications
    3. Search for your Azure Function’s Managed Identity
    4. Go to Permissions
    5. Click Add permission
    6. Select Microsoft Defender for Endpoint
    7. Choose Application permissions
    8. Add one of the following:
      • Ti.ReadWrite
      • or Ti.ReadWrite.All

    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.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.