Layer7 API Management

Portal Template - LAC Authorization Header 

Sep 04, 2018 02:26 PM

Hello API team!

 

I'm sharing a simple Portal Template I built that will add the Live API Creator Auth Token as an Authorization header. To get this working I had to change the Portal Sync API schedule job too. I don't know if this is officially supported, but it can be very handy when doing demos or POCs. This is a screenshot of the template:

 

The template will receive one of the LAC Auth Token. You can either use one of the existing or create a new one. It's up to you. This is where you can find those tokens within LAC, just in case you don't know. As you can see the token configured with the template match the LAC one:

 

The first thing you need to do is to create a new Portal Template. If you have never created one before, just follow this documentation. I also attached the policy I created just in case you wanted something to start with. This is the policy I created:

 

And this is the content of the assertion number 8, with the variables I'm exporting from the policy:

 

Side note: The only thing I'm doing with the template is to expose the LAC Auth Token to be used later. You could call the LAC authorization API and get an apikey and use it too. This was the way I found better. Feel free to change it to match any requirement you may have.

Now the tricky where the magic happens: changing the OOB Portal Sync API. This is a schedule policy found inside the API Portal Integration folder, as follows:

 

A little disclaimer before you continue: As I said before this might not be supported, so please, be careful sharing this with customers or partners. Secondly I only changed the service creation policy bundle. That means, if you update your API you will probably loose something. Feel free to use the techniques I used to change the other bundle import too. Before you change anything with that policy, I suggest you to duplicate the original lines and disable them, just in case you want to rollback.

Open up the Portal Sync API task policy and go to the line 137. You're going to find the original XML of the policy placed when a new API is published to the Portal. Duplicate the proxyXml variable set and disable the original one. You can also add a comment to both of them to make it easier for you to go back there late. You can now copy the content of the proxyXml (double click on it) and create a new dummy API anywhere within your gateway. Then paste the copied content and you're going to get the policy that's added when a new API is published. I changed the HTTP routing to include the LAC Authorization Header if it's available. This is how my policy looks like:

 

 

When you're done with your custom policy it's time to convert it and you would need to make some few changes to make sure the variables are available when the the gateway triggers that policy to create your new API. That's because you need to replace the $ by $ and also add other few things that are missing. I suggest you to save both the original XML and the one you made the changes and compare it like this:

One thing that you're going to need to add manually is the portal service preface, as follows:

 

I attached both XML to this document so you can use it as a reference. After finishing the replacement of the $, on the variables, you can now copy the content of your changed XML and update the Portal Sync API back again, with your changes. Save and Activate and give it a try by adding a new LAC API to your portal, then add your new template and do not forget to add a valid LAC Authorization Token. Wait for everything to synchronize and test it!

 

I hope this was useful!

Statistics
0 Favorited
7 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
zip file
tutorial.zip   8 KB   1 version
Uploaded - May 29, 2019

Related Entries and Links

No Related Resource entered.