set REST API basic authentication

set REST API basic authentication

  

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?

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

Solution

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?

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

ok, thank you very much for the help