Introduction
In my last article, I have introduced the procedures of creating a simple api and applying basic authentication to mule application. I am going to introduce another simple API security mechansim for mule application - Client ID Enforcement.
Both Basic Authentication and Client ID Enforcement are simple security mechanisms. Combining with Https, they can provide basic security for most applications. Nowadays, oauth2 is more popular security scheme for API security. I will cover that in my later post.
The complete source for this post are available at my github: https://github.com/garyliu1119/api-manager-explainedSetup In Anypoint Platform
First I create a new API project, namely, accounts-manager as shown in the following snapshot:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #%RAML 1.0 title: Account Api version: 1.0.1 protocols: [ HTTP, HTTPS ] baseUri: http: //esb.ggl-consulting.com/{version} mediaType: application/json traits: client-id-required: queryParameters: client_id: type: string client_secret: type: string types: Account: properties: id: integer type: string name: string Error: properties: code: integer errorMessage: string /accounts: /{id}: get: is: [client-id-required] description: get an account information by id responses: 200: body: application/json: type: Account example: { "id" : 1234, "name" : "Gary Liu" , "type" : "checking" } |
After save the API, we need to publish the API to Exchange. In the exchange, we need to request access. By doing this we get client ID and client secret as shown in the following snapshot:
These client ID and client secrets will be available to the customers who consumes the API. These values can (should) be reset periodically.To apply security scheme of client id enforcement, we can check the radio button of "Client ID enforcement" as shown below:
The easiest way is take the default configuration of "Custom Expression" as shown below: That is all we need to do on the Anypoint Platform. Next, I will demonstrate the procedures to setup Mule applications.Setup In Mule Application
The setup for the Mule application is the same as those shown in the simple security. We need to create a new Autodiscovery component like the following:
1 2 | <api-platform-gw:api apiname= "groupId:d1ba8782-0846-4b64-9ced-e68e7a9c952e:assetId:accounts-manager" version= "1.0.1:9177708" flowref= "accounts-main" create= "false" apikitref= "accounts-config" doc:name= "API Autodiscovery" > </api-platform-gw:api> |
Invoke Application
To invoke the application, we need to pass the client_id and client_secret paraters as query parameters as shown in the following snapshots:Client ID and Secret As Header
In the above section, I have demonstrated the simple way to pass client id and client secret. That is pass the client id and secret as query parameters. Apparently, this is not secure. The alternative is to pass the encrypted client id and secret as headers. The configuration is shown as the following:
There is no changes on application. The only change is how the client invoke the application. Consumers will need to invoke the application with the way as shown below:
Summary
In this post, I have demonstrated the procedures to applying security policy of client ID enforcement. There are two ways to do so:- Custom configuration: passing client_id and client_secret as query parameters of headers
- Passing client id and secret as base 64 encrpted header
the blog is good and Interactive it is about Mulesoft API Developer it is useful for students and Mulesoft Developers for more updates on Mulesoft mulesoft Online training
ReplyDelete
ReplyDeleteThank you.. This is very helpful. . Mulesoft online Course Bangalore
Thanks for sharing such a nice blog.
ReplyDeleteMulesoft Online Training
Mulesoft Training in Hyderabad
ReplyDeleteThank you for sharing wonderful information with us to get some idea about that content.
Mulesoft Training in Hyderabad
Mulesoft Online Training
I really liked your blog post.Much thanks again. Awesome
ReplyDeletemulesoft self learning
mulesoft online Course in Hyderabad
ReplyDeleteThank you for sharing such a great information
Mulesoft Training in Hyderabad
Mulesoft Online Training in India