Reputation: 1728
I was asked to refactor an AWS Lambda (using Python) which calls an Azure Logic App.
When I run my Lambda, it gets a 202 (accepted) response. In Azure, I can see the request failed with the following error:
{
"error": {
"code": "AuthenticationFailed",
"message": "Authentication failed. The 'Authorization' header is missing."
}
}
As the error says, an authorization header is missing. Odd thing is, the previous code base which was working until recently, doesn't appear to provide any authorization header either.
Here's my code:
import requests
import json
url = "https://prod-01.northcentralus.logic.azure.com:443/workflows/sensitive/triggers/manual/paths/invoke?api-version=2016-10-01&sp=%2Frun%2Fbook%2Fsp&sv=1.0&sig=sensitive"
body = {
"company": "X",
"owner": "[email protected]"
}
requests.post(url, data=json.dumps(body), headers=headers)
The old lambda's code is essentially identical. When I copy+paste the relevant part into my lambda, I get the same error.
As I said, this was supposedly working fine until recently.
All of my reading online suggests that I need a bearer token generated using a service principal.
I've been trying to figure out how to piece this request together bit by bit using Postman. But the posts I've found online explaining how to do just this don't work when I try them. (When I try this post, it says I should get an Invalid Auth Key
response in Postman. But I just get the same 202 response.
And I noticed that one of the params encoded in the logic app's url is sp=%2Frun%2Fbook%2Fsp
or sp=run/book/sp. Is this somehow related to the service principal? I don't have access to Azure Active Directory to check it out.
Thanks much!
Upvotes: 0
Views: 2252
Reputation: 1440
The authorization header should be a JSON Web Token that you obtain from Azure Active Directory, directly from Azure Portal.
You can solve the problem you are facing by adding authorization header to your HTTP request. And as a value for it, provide 'Bearer', followed by a space and then the token. After that send the request and it should work fine.
And the Authorization header should be in like:
Authorization : Bearer TOKEN
.
Check this Redeem a code for an access token section of this Microsoft Document to know how can we obtain a JWT from Azure Active Directory.
For more information you should also check this Authenticate Postman against Azure Service Management API document.
Upvotes: 1