Search code examples
apioauth-2.0access-tokenidentityserver4azure-api-management

Generate Access Token and validate against IdentityServer4 through Azure API Management


I have an external endpoint which is going to hit the Azure API gateway and that would route it to the backend API which is protected by IdentityServer4 authorization.

I am getting the access token if I hit it through the Postman client with the interactive UI from IdentityServer.

Is there a way I can get the access token required from the Azure API Management to validate against the IdentityServer4 and append it to the header in the request to the backend API?


Solution

  • Yes it is possible to achieve it through custom policy. You can ask your external API-Client/Consumer to paas in credentials in heaser, and then you write a policy inside inbound to can read those user credentials and do a API request (similar to your postman) and get the access token. You can then append the same token and let your request gets forwarded to backend API.

    As per your problem statement, this should work. In case not, you might have to explain your scenario with more description/steps.

    Here are some of the reference materials for you, I hope it helps.

    https://learn.microsoft.com/en-us/azure/api-management/api-management-advanced-policies#SendRequest

    https://learn.microsoft.com/en-us/azure/api-management/api-management-sample-send-request