254
Views
14
Comments
Solved
API Authorization Using token

Hello Community,

I'm using consume API for fetching Data from Azure Portal. 

Firstly, I fetched token value by passing credentials in the Post Request. After getting my token value I want to fetch data by passing Subscription ID and other parameters. 

In Authorization Part I'm passing "Bearer" + "Token value" but it is giving invalid token id and authorization is provided in invalid format.


Can anyone help me how to fetch values from token value?

Thank you.

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi,

no, the error indicates that the Authorization header itself is missing. If you have the wrong scopes you get another error 403.

Delete that OnBeforeRequest action. You dont need it. At least for simple API calls to Azure/Graph.

Check the configuration of your Authorization Input Property. Should look like this


Send In Header is important!

The input parameter must contain the word "Bearer" followed by space then followed by your Azure OAuth Token.


You can also check out my article here https://medium.com/itnext/getting-started-with-outsystems-and-microsoft-graph-123006356d41

This explains the steps to use Graph API, but the procedure is the same for Azure Management API.

Best

Stefan

2022-07-22 08-49-20
Laura Fidalgo

Hi,

Have you tried adding your token directly to the API header? I can see from your screenshot that your 'Authorization' field is empty, and that your error message says 'The authentication failed because of missing 'Authorization' header".

You should have something like this

here i have a function to return the token, but you h=can have what fits your solution.

Hope this helps!

UserImage.jpg
Dev Limbachia

Hello Laura,

Thank you for your response.

Can you tell me from where I can get this GetToken action? I searched in dependencies but not found :(

2022-07-22 08-49-20
Laura Fidalgo

Any time :) 

This was built by our team, there's no dependency you can add to your app. You need to add your data instead of the 'GetToken' function that you see there. Add you '"Bearer" + "Token value" '

UserImage.jpg
Dev Limbachia


As per your advice, I tried this also. But the error is same.

Is there any other way to solve this? I ran my hands back and forth and browsed a lot but didn't find any. 


2022-07-22 08-49-20
Laura Fidalgo

did you remove the previous authentication logic? The one you have in the assigns?

UserImage.jpg
Dev Limbachia

Yes I did.

I'm stuck on this since 2 weeks

2022-07-22 08-49-20
Laura Fidalgo

But you still have the logic in the on before request

UserImage.jpg
Dev Limbachia

Yes Ma'am,

I deleted the logic after you said and checked again, but the error was same 

2021-10-09 07-57-44
Stefan Weber
 
MVP

In your Screenshot above you assigned something to the Basic Authentication. That is incorrect for Bearer Token Authentication.

Add to the Authorization Header "Bearer " + YourToken. Please note the space between Bearer and your token. and leave the basic credentials empty.

Also make sure that you have associated the rights permission scopes in your Azure App registration.

Stefan

UserImage.jpg
Dev Limbachia

Hello Stefen,

Thank you for your response.

Is it possible that if I haven't associated the permissions scopes then this message will appear?

As the error shows regarding authorization and bearer token.

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Hi,

no, the error indicates that the Authorization header itself is missing. If you have the wrong scopes you get another error 403.

Delete that OnBeforeRequest action. You dont need it. At least for simple API calls to Azure/Graph.

Check the configuration of your Authorization Input Property. Should look like this


Send In Header is important!

The input parameter must contain the word "Bearer" followed by space then followed by your Azure OAuth Token.


You can also check out my article here https://medium.com/itnext/getting-started-with-outsystems-and-microsoft-graph-123006356d41

This explains the steps to use Graph API, but the procedure is the same for Azure Management API.

Best

Stefan

UserImage.jpg
Dev Limbachia

Thank you Stefen,

I Followed your steps,


But it is coming same :(

2021-10-09 07-57-44
Stefan Weber
 
MVP

Yes, because you didnt fill in the Authorization Header. Here you have to put in "Bearer <Token>". The Test windows does not respect other transformations or configurations you made.

UserImage.jpg
Dev Limbachia

Thank You @Stefan Weber  and @Laura Fidalgo for your help.

The error is Solved.

Thank you @Stefan Weber  again for your blog you provided. It is so helpful.

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