I have a policy on all my operations in Azure API Management to validate a JWT Token and extract the sub
Claim, which I store in a userId
variable that can be used in other policies.
I have an operation called Organization Add
that calls an Azure Function to add an organization to the database.
The Azure Function expects a value for userId
in the body.
My policy for the Organization Add
operation needs to add the userId
to the body.
To do this I convert the incoming message body to a JObject
and then add the property and assign it the value of the userId
variable.
I tried, unsuccessfully, to use the variable inline using Liquid templates.
Took some time, but finally figured out how to do it thanks to this question posted on the Microsoft forums https://social.msdn.microsoft.com/Forums/en-US/3bb42ca6-adc4-4c70-ae31-a54b9d75ea10/sending-json-inside-policy-definition.
Hope this saves a fellow developer some time!
Discover more from Matt Ruma
Subscribe to get the latest posts sent to your email.
Thanks for this blog.
I was looking for a way to extract user id from the JWT token in the API management and send it as a query string to the backend. This blog helped me lot and saved a lot of time for me.
Thanks for sharing.