【问题标题】:How to authenticate when calling Azure Logic App?调用 Azure Logic App 时如何进行身份验证?
【发布时间】:2021-12-23 13:18:57
【问题描述】:

我被要求重构一个调用 Azure 逻辑应用程序的 AWS Lambda(使用 Python)。

当我运行 Lambda 时,它会收到 202(已接受)响应。在 Azure 中,我可以看到请求失败并出现以下错误:

{
  "error": {
    "code": "AuthenticationFailed",
    "message": "Authentication failed. The 'Authorization' header is missing."
  }
}

正如错误所说,缺少授权标头。奇怪的是,之前的代码库直到最近才工作,似乎也没有提供任何授权标头。

这是我的代码:

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": "bob@email.com"
}

requests.post(url, data=json.dumps(body), headers=headers)

旧 lambda 的代码基本相同。当我将相关部分复制并粘贴到我的 lambda 中时,我得到了同样的错误。

正如我所说,这应该直到最近才正常工作。

我所有的在线阅读都表明我需要一个使用服务主体生成的不记名令牌。

我一直在试图弄清楚如何使用 Postman 将这个请求一点一点地拼凑在一起。但是我在网上找到的解释如何做到这一点的帖子在我尝试时不起作用。 (当我尝试 this post 时,它说我应该在 Postman 中得到 Invalid Auth Key 响应。但我只是得到相同的 202 响应。

我注意到逻辑应用的 url 中编码的参数之一是 sp=%2Frun%2Fbook%2Fsp 或 sp=run/book/sp。这是否与服务主体有关?我无权访问 Azure Active Directory 来检查它。

非常感谢!

【问题讨论】:

  • “在 Azure 中,我可以看到请求失败并出现以下错误” - 您在 Azure 中究竟在哪里看到此错误?可以提供截图吗?如果您从 Logic App 收到 202 响应,则表示它已成功触发,没有授权问题。

标签: rest aws-lambda https azure-logic-apps azure-rest-api


【解决方案1】:

授权标头应该是您从 Azure Active Directory 直接从 Azure 门户获取的 JSON Web 令牌。

您可以通过在 HTTP 请求中添加授权标头来解决您面临的问题。作为它的值,提供“Bearer”,后跟一个空格,然后是令牌。之后发送请求,它应该可以正常工作。

授权头应该是这样的:

Authorization : Bearer TOKEN.

查看此 Microsoft 文档的 Redeem a code for an access token 部分,了解我们如何从 Azure Active Directory 获取 JWT。

有关更多信息,您还应该查看此Authenticate Postman against Azure Service Management API 文档。

【讨论】:

  • 感谢您的明确指导。我要试试这个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-08
  • 2019-07-27
  • 2019-09-08
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多