There are many applications that use HMAC-based authentication (for example Microsoft Teams’ chat bot). This blog explains how to create a reusable custom policy with MuleSoft Anypoint Platform in order to authenticate requests from applications using HMAC authentication.
[HMAC is a specific type of message authentication code. The client sends the HMAC original message (not encrypted) along with the hash. The server side receives the message and, using the secret token of the server, hashes the message to compare it with the received hash. If there is a match, then the authentication passes; if not, the authentication is declined.]
Steps to create a reusable custom policy for HMAC authentication:
*the sample groovy script needs to be added to the ‘before’ section of the policy xml file.
In this stage you can also specify message filters to apply if the inbound hash is null or not equal to the generated hash. The filters can refer to the processor chains which need to be defined outside the ‘before’ section of the policy.
Now the HMAC-based client application can now test our Mule application to which we attached the policy.
If you would like to find out more about Anypoint Platform and how to enable HMAC authentication, we can help. Give us a call or email us at Salesforce@coforge.com
Other useful links:
How APIs can modernise legacy systems
API Recipes with MuleSoft Anypoint Platform