1108
Views
6
Comments
Solved
set REST API basic authentication
Question

Hello.

I'm developing a mobile app which is consuming a REST API that requires basic authentication. I need the username/password values to come from a user input. However, I don't seem to understand how to set those values other than by hardcoding them in the required field.

What's the way to do this?

João Amorim
Rank: #0
Solution

Hi Ricardo

To do this dynamically you'll have to build the Authorization header yourself. The correct format is:

"Basic " + EncodeToBase64(username:password)

In a REST API, add an input parameter with the name Authorization that is sent in header:

Then add the reference to the methods BinaryToBase64 and TextToBinaryData from the BinaryData extension, and assign the following value to the input parameter:

Let me know if it works for you

Rank: #14436

Hi, I have problem when I try to use "TextToBinaryData" and "BinaryToBase64" in outsystems 11, it showed Unknown function for both "TextToBinaryData" and "BinaryToBase64".


João Amorim wrote:

Hi Ricardo

To do this dynamically you'll have to build the Authorization header yourself. The correct format is:

"Basic " + EncodeToBase64(username:password)

In a REST API, add an input parameter with the name Authorization that is sent in header:

Then add the reference to the methods BinaryToBase64 and TextToBinaryData from the BinaryData extension, and assign the following value to the input parameter:

Let me know if it works for you



1591545918310.jpg

Rank: #12322

It worked perfectly, thank you!

Just one more question, is it possible to do it for the REST API itself, instead of doing it in every request?

João Amorim
Rank: #0

Unfortunately you'll have to add the header for each method, but you can encapsulate the encoding part in a single function to be reused

Rank: #12322

ok, thank you very much for the help

Rank: #575

Hi @df fe,

You will need to start using dependencies (via Manage Dependencies window in Service Studio) of the actions "TextToBinaryData" and "BinaryToBase64". They are in the BinaryData producer module.