485
Views
5
Comments
Consume API with Authentication using Bearer Token.

I'm trying to incorporate using of a API which has bearer Authentication type. I tried by passing Authentication in the headers section, but couldn't achieve it. And need some suggestions in generating the token dynamically.

I have referred this below discussion.
https://www.outsystems.com/forums/discussion/73029/api-expose-consume-add-authentication-using-bearer-token/

But couldn't comprehend it properly. If someone could mention a step wise guide, it would be very helpful for many who are trying to achieve something similar.

2024-01-18 12-42-28
Bogdan Boglea

Hello,


In your consumed REST API action you should add an input parameter that has the Send In value set to Header (see screenshot below):


When calling this API inside one of your server actions make sure to pass in the value as Bearer followed by a space and then your OAuth2 token.



Hope this helps,

Bogdan

2022-12-26 17-01-33
Muhammad Agung A Djafar

thanks, this is very helpful

UserImage.jpg
Gowrisankar JG

Do we have to whitelist this outsystems url? I gave this a try but was always getting 401.
And could you also mention something regarding the token generating part?

2023-02-26 23-17-33
Kshitij Raheja

Hey @Gowrisankar JG,

To Implement Dynamic API Auth there are a few methods possible i have implemented Microsoft Graph auth in the OML you can check it out

1) Create site properties to save auth tokens

2) Create a get token rest API to get the auth token using the client ID and secret or your preferred auth method

3) to generate a new auth token add "OnBeforeRequest" and in headers append "authorization"

please make sure to use it safely and use proper authentication for the API
Hope this helps

Regards,
Kshitij Raheja

APIDynamicAuth.oml
2022-12-30 07-28-09
Navneet Garg

did you get the solution ?

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.