【发布时间】:2015-03-12 20:24:43
【问题描述】:
我正在尝试执行“客户端凭据”流程并获取 Office 365 应用程序的访问令牌。我按照以下步骤操作。
第 1 步:我按照以下文档在 azure AD 上注册了应用程序 http://blogs.msdn.com/b/exchangedev/archive/2015/01/21/building-demon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow.aspx?CommentPosted=true#commentmessage
第 2 步:为我的应用程序配置 X.509 公共证书。下载清单文件并更新“KeyCredentials”值并再次上传清单(按照第 1 步文档)。
"keyCredentials": [
{
"customKeyIdentifier": "BB/OLYBBivt4RXUKxQbk+c9UEmo=",
"endDate": "2016-12-15T07:00:00Z",
"keyId": "6837d367-660c-4d44-b0ea-9dcd538828e5",
"startDate": "2014-12-15T07:00:00Z",
"type": "AsymmetricX509Cert",
"usage": "Verify",
"value": null
}
第三步: 按照中的步骤 Office 365 Rest API - Daemon week authentication 生成“客户端断言”,如下所示。
base64(header).base64(payload).base64(siganature)
标题如下:
{
"alg": "RS256",
"x5t": "BB/OLYBBivt4RXUKxQbk+c9UEmo=" //same as customKeyIdentifier
}
有效载荷为:
{
"aud": "https://login.windows.net/<tenantid>/oauth2/token",
"exp": "now + 1 hour",
"nbf": "now",
"iss": "CLIENT ID",
"jti": "SOME GUID",
"sub": "CLIENT ID"
}
对于签名(RSA-SHA-256算法),我使用了openssl,如下所示。
openssl dgst -sha256 -sign privatekey.pem < input.txt > signature
注意:input.txt 包含base64(header).base64(payload)
第四步: 当我发出获取访问令牌的请求时,出现如下“无效签名”错误
{
"error": "invalid_client",
"error_description": "AADSTS70002: Error validating credentials. AADSTS50012: Client assertion contains an invalid signature.\r\nTrace ID: 880b11db-0935-4cbd-836e-4d4d91b2a9e2\r\nCorrelation ID: e72ae39a-9868-4efe-847e-890ef32d48ae\r\nTimestamp: 2015-03-12 18:45:54Z",
"error_codes": [
70002,
50012
],
"timestamp": "2015-03-12 18:45:54Z",
"trace_id": "880b11db-0935-4cbd-836e-4d4d91b2a9e2",
"correlation_id": "e72ae39a-9868-4efe-847e-890ef32d48ae",
"submit_url": null,
"context": null
}
我在 RSA SHA256 签名中做错了什么?
任何帮助将不胜感激。
注意:我什至在 python 中使用了“PyJWT”,在 nodejs 中使用了“jsonwebtoken”来生成客户端断言(JWT 令牌)并将其用于令牌请求,我得到了同样的错误。
【问题讨论】: