I have an Azure Application name and I can access the enterprise application properties with the help of graph Api.
I want to integrate the below graph Api into my APIM service for fetching the properties. Is there any reference for creating a mock Api in Api management service?
Microsoft Graph:
GET https://graph.microsoft.com/v1.0/servicePrincipals/?$filter=displayName eq 'Demo App' &$select=appId,appDisplayName
can i use the policies "rewrite-uri" for generating token and then pass it to the "send-request".
or is there any simple way available for integration?
Initially, I registered one application and granted Application.Read.All
Microsoft Graph permission of Application type with admin consent as below:
Make sure to add redirect URI as "https://authorization-manager.consent.azure-apim.net/redirect/apim/YOUR-APIM-SERVICENAME" in Web
platform of application as below:
Now, create credential provider in your APIM service with Identity provider as Azure Active Directory v1, grant type as client credentials and resource URL as https://graph.microsoft.com like this:
Under Connection
tab, enter client ID and client secret values of your app registration with connection name:
You can confirm it by checking the status of connection, visiting newly created credential provider like this:
Create new HTTP API with "https://graph.microsoft.com/v1.0" as Web service URL:
Create GET operation in it with URL as /servicePrincipals
:
Make use of below sample policy file code that generates token and use it to call Graph API:
<policies>
<inbound>
<base />
<get-authorization-context provider-id="graphcred01" authorization-id="graphconnection" context-variable-name="auth-context" identity-type="managed" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + ((Authorization)context.Variables.GetValueOrDefault("auth-context"))?.AccessToken)</value>
</set-header>
<!-- Rewrite URI to include filter and select parameters, with properly escaped characters -->
<rewrite-uri template="/servicePrincipals/?$filter=displayName eq 'DemoApp'&$select=appId,appDisplayName" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
Response:
Reference:
Create connection to Microsoft Graph API - Azure API Management | Microsoft