Azure 应用程序清单中的 "encryptedSecretValue" 参数应该是什么?

What should be in the "encryptedSecretValue" Parameter in an Azure app manifest?

我正在尝试将 OAuth 身份验证与针对 Office365 的 Exchange Web 服务 (EWS) 结合使用。这是在成功将 OAuth2 与新 RESTful Graph API 一起使用之后,但发现 Graph API 没有执行我需要对机密客户端 "app-only" 流程执行的操作(这将由守护进程使用,因此没有用户交互)。

在我的办公桌上敲了几个小时的额头后,我发现(我希望!)与机密客户端 OAuth 授权 headers 的 EWS SOAP 交易必须具有使用 X.509 证书创建的不记名访问令牌,不仅仅是可以与 RESTful 图 API 一起使用的 client_id/client_secret。否则,EWS SOAP 将失败并显示 401 Unauthorized HTTP return,以及一个名为 x-ms-diagnostics 的额外 non-standard header,其值为:

2000001;reason="The access token is acquired using an authentication method that is too weak to allow access for this application. Presented auth strength was 1, required is 2.";error_category="invalid_token"

不幸的是,Azure 管理门户没有用于管理这些证书的 UI,因此您必须下载、编辑然后上传应用程序的清单(一个 JSON 文件)。

我创建了一个 self-signed 2048 位 X.509 证书(使用 openssl 生成一个名为 cert.pem 的 PEM 文件和一个名为 key.pem 的文件中的密钥),然后生成了一个来自 cert.pem 的 base64 编码指纹使用:

echo $(openssl x509 -in cert.pem -fingerprint -noout) | sed 's/SHA1 Fingerprint=//g' | sed 's/://g' | xxd -r -ps | base64

我按照 this document 的第 2 步中的说明尝试将证书放入清单​​(与现有的 Graph API client_id/client_secret 设置一起,因为我仍然想使用nicer/more 现代 RESTful 图形 API 尽可能在应用程序中)。为此,我向 JSON 文件中的 passwordCredentials 数组添加了一个新的数组元素数据结构:

{
  "customKeyIdentifier": "<base64EncodedFingerprintFromAbove>",
  "keyId": "<guid>",
  "endDate": "2018-11-24T09:12:01.397205Z",
  "type": "AsymmetricX509Cert",
  "usage": "Verify",
  "value": "MIIDvTCC (lots of certificate) cskQ=="
}

然而,当我现在尝试使用 Azure 管理门户上传编辑后的清单时,出现错误:

ParameterValidationException=Invalid parameters provided; BadRequestException=Encrypted secret cannot be empty and can be at most 1024 bytes. Parameter name: encryptedSecretValue;

我的清单 JSON 文件中没有名为 encryptedSecretValue 的参数,而且我无法通过 Google on what this error means or what should go in this parameter.

找到任何内容

所以我的问题是:应用程序清单 JSON 文件中应该包含哪些内容,以允许使用证书获取机密客户端访问令牌,以便通过 EWS SOAP 查询进行 OAuth 授权?我是不是找错树了?另外,假设我可以让它与 SOAP 一起工作,我可以将生成的访问令牌与 RESTful Graph API 调用以及 EWS SOAP 调用一起使用吗(即混合和匹配 Graph 和 EWS 在同一个守护程序)?

passwordCredentials 用于共享 secret/password(这就是 UI 中显示的内容)。

您需要使用 keyCredentials 以获得 X509/asymmetric 密钥支持。因此,将您的 JSON 包裹在上面:

    "keyCredentials": [ 
       put your JSON block from above right here
    ]

未来我们希望有一个UX可以完全简化这个痛点,并实现简单的证书上传。然而,这就是我们现在所拥有的。

希望这对您有所帮助,