我无法启动Microsoft Graph webhook订阅(特别是对于邮箱) . 在启动订阅时,似乎Microsoft接受我发送的所有参数以配置订阅但未通过总订阅,因为它从我已配置的 endpoints 接收到非2xx响应 .
我的 endpoints 将 401
发送回Microsoft的原因是因为包含订阅验证令牌的POST缺少clientState .
我使用clientState键值对来验证Microsoft和我的 endpoints 之间的所有通信 . 如果我的 endpoints 没有看到正确的clientState,它将返回 401
.
关于我可能缺少什么的想法,或者我是否应该以不同的方式解决这个问题?在我看来,允许我的 endpoints 接受未经身份验证的GET / POST不是一种选择 .
示例请求正文使用POST方法,包括 Headers 中的API密钥:
{
"changeType": "created",
"clientState": "testClientState",
"resource": "users/<UserName>/messages",
"expirationDateTime": "2017-08-10T10:24:57.0000000Z",
"notificationUrl": "<EndpointURL>"
}
从Microsoft返回错误:
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request failed. Must respond with 200 OK to this request.",
"innerError": {
"request-id": "adf7fc7b-6b14-4422-8526-c1391be8dd27",
"date": "2017-08-07T16:24:59"
}
}
我理解一切按预期工作,直到我的 endpoints 被发送验证令牌,因为我收到验证令牌,但我的 endpoints 拒绝它,因为它缺少客户端状态 .
endpoints 日志片段:
queryStringParameters": {
"validationToken": "<ValidationToken sent by Microsoft>"
}
我的API endpoints 逻辑基于Microsoft的一些开发人员指南 . 特别是对于订阅创建我是using this guide .
1 回答
我代表Microsoft Graph Web钩子团队......
我们在MS Graph服务日志中验证了您的请求,并确认它在订阅验证阶段失败,因为您的终端的HTTP状态代码='未授权'...根据您的观察,一切都是正确的...
By design, MS Graph Web hooks do not send the clientState header as part of the Subscription validation request. 在订阅验证期间,请不要期望此标头 .
更多信息
您可能希望在验证请求标头中收到clientState,因为Office365图表会将其发送给https://msdn.microsoft.com/en-us/office/office365/api/notify-rest-operations . Office 365图表与MS Graph不同...
这个问题在https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/subscription_post_subscriptions观察到一些文档改进...示例发布者通知有效负载,在成功订阅之后与订阅验证一起提到...我们修复了这些 .