How to consume rest api with cookie based authentication

How to consume rest api with cookie based authentication

  

I built a web api on .Net, and now to consume it, I need to send a cookie with the authorization token. In this video the work is done using Fiddler and it seems to be easy. How do I achieve this in Outsystems? I'm still using 9.1 version.


Hi Samy,


You have 2 ways of adding cookies: either just adding a header called "cookies" to your request or going in OnBeforeRequestAdvanced and add it in C#/Java on the request.


But I looked at the video that you liked and fiddler UI is actually very misleading. Note that it says "Cookie / Login" ...and it that section it includes more than just cookies.

What you actually need is a header called "authorization" with that value, not really a cookie.


The easier way to add a header is at the client level, by adding an input with Send In Header on your action or inside a OnBeforeRequest callback. 

Regards,
João Rosado


João Rosado wrote:

Hi Samy,


You have 2 ways of adding cookies: either just adding a header called "cookies" to your request or going in OnBeforeRequestAdvanced and add it in C#/Java on the request.


But I looked at the video that you liked and fiddler UI is actually very misleading. Note that it says "Cookie / Login" ...and it that section it includes more than just cookies.

What you actually need is a header called "authorization" with that value, not really a cookie.


The easier way to add a header is at the client level, by adding an input with Send In Header on your action or inside a OnBeforeRequest callback. 

Regards,
João Rosado


Thank you for your reply

Using PostMan client, I already tried to add just a header called authorization and it failed to connect saying "Authorization has been denied for this request". I then made this topic on Stack Overflow asking about the failure, and the answer was that my web api out of the box authentication is cookie based. That's why I am asking then, how I make this approach to work consuming the api through Outsystems.

After reading my code on Stack Overflow, you still think that I could connect without a cookie?


Well, I personally never tried to create a owin rest server, so I'm not sure what some of that code is doing.


The only pointer that I can say is that what the video is showing has nothing to do with cookies. 


Regards,
João Rosado


SamyCode wrote:

I built a web api on .Net, and now to consume it, I need to send a cookie with the authorization token. In this video the work is done using Fiddler and it seems to be easy. How do I achieve this in Outsystems? I'm still using 9.1 version.


Samy,

I created a screencast where you can see how we can authenticate using rest api in OutSystems.

Using header authentication and body used for send some information to the rest api


Rest With Header Authentication


Any doubt dont hesitate to contact .. :-)


PS.: Execute the html file locally (VirusFree)