Role Based API Operation Access in APIM with Validate JWT Policy
    • Dark
      Light
    • PDF

    Role Based API Operation Access in APIM with Validate JWT Policy

    • Dark
      Light
    • PDF

    Article Summary

    #ServerlessTips - Azure Functions
    Author: Mandar Dharmadhikiri Business & Integration Architecture Manager

    The Azure API Management service provides an inbuilt validate jwt policy to enable Client Credentials OAuth 2.0 flow . The bare minimum validation that you can implement is to have the aud and appId claims validated to ensure that the correct client app is calling the correct API. This can be done by using the validate JWT token policy as shown below.

    download - 2023-08-04T151050.663

    This approach is restrictive in nature. If you have CRUD operations for an API, then defining this policy on all operations will grant the consumer the CRUD rights on the API. You may want to restrict certain apps to provide only selective rights. Let’s consider that you only want to grant the Read rights to a consumer.

    You start by defining the app roles in the app registration which represents the API being consumed. A sample is shown below

    download - 2023-08-04T144809.890

    Now you can amend the validate jwt policy to check for this app permission. It can be done as shown below
    download - 2023-08-04T151210.932

    If for another application you want to give both read and create permission, you can define the jwt policy on create as follows

    download - 2023-08-04T151318.358

    This way you can add role-based authorization to the different operations of the API.

    MicrosoftTeams-image 443


    Was this article helpful?