Using site properties as REST Authentication

Using site properties as REST Authentication

  

So we're using an API which has the usual APIKey and APISecret, and we needed to update this information from time to time so we created a simple configuration page and store these values in Site properties. 

The REST methods require these values of course but when you set up to consume a REST API, you have the Basic authentication fields which we populated manually. The fields Username and Password do not accept variables.

Is there any way to configure it so it goes to read the site properties where this information is stored?

Hi

You can create 'Getters' for you Site Properties. That is, create a public action (set as a function if you wish) in the module you stored your Site Properties that the only thing it does is output the value of your site property.

Then, in the module where you use your REST service, simply reference that action to get the value of the Site Property you want.

Cheers,

João Mateus

Hi Mariano,

You have two options to do that:

1) In Service Center, you have in the Integration Tab, access to your COnsumed REST APIS. There is possible to input a net Effective URL and also Effective Username and Password, just like the site properties variables works.


2) Other options is use the Authorization header for your calls, like this post suggest https://www.outsystems.com/forums/discussion/22162/set-rest-api-basic-authentication/


Best Regards

Fabio Fantato


Thanks for your answers,

João, unfortunately I'm not quite following you. The Basic auth fields username and password will not take anything other than hard text as inputs, so no actions can be referenced.


Fabio,

1) You're suggesting using this configuration page in the ServiceCenter instead of going through the config page we built in the eSpace, correct? 

This probably works fine, although it's not very user friendly, could be a solution

2) This also seems like a solution, but if I understood correctly, I'd have to add these headers to every single consumed REST method?

You can use he OnBeforeRequest (it will be apply to all your consumed method). 

In this method you can change your request, adding into header the authorization parameter dinamically.


Solution

Okay, so this works. For anyone interested, added an OnBeforeRequest action as suggested, then added an Assign action with two assignments: 


Request.Headers.Current.Name 

= "Authorization"


and 


Request.Headers.Current.Value

= "Basic " + BinaryToBase64(TextToBinaryData(Site.APIKey + ":" + Site.APISecret))



Needs the BinaryData dependency.


Thank you both!

Solution