0

Microsoft webhook 订阅正在发送奇怪的正文数据,并且validationToken参数中没有文本。Microsoft Graph 团队中是否有人可以提供帮助?

这就是我要发送的内容(notificationUrl为了隐私,我更改了实际域名)。

{
    "changeType": "created",
    "notificationUrl": "https://myapp.com/version-test/api/1.1/wf/msgraphvalidation",
    "resource": "me/mailFolders/inbox/messages",
    "expirationDateTime": "2018-08-27T18:23:45.9356913Z"
 }

这是在将带有上述信息的 POST 发送到“ https://graph.microsoft.com/v1.0/subscriptions ”或“ https://graph.microsoft.com/beta/subscriptions ”后在正文中返回的内容.

Request data
{
    "bold": "\u001b[1m\u001b[22m",
    "underline": "\u001b[4m\u001b[24m",
    "strikethrough": "\u001b[9m\u001b[29m",
    "italic": "\u001b[3m\u001b[23m",
    "inverse": "\u001b[7m\u001b[27m",
    "grey": "\u001b[90m\u001b[39m",
    "black": "\u001b[30m\u001b[39m",
    "yellow": "\u001b[33m\u001b[39m",
    "red": "\u001b[31m\u001b[39m",
    "green": "\u001b[32m\u001b[39m",
    "blue": "\u001b[34m\u001b[39m",
    "white": "\u001b[37m\u001b[39m",
    "cyan": "\u001b[36m\u001b[39m",
    "magenta": "\u001b[35m\u001b[39m",
    "greyBG": "\u001b[49;5;8m\u001b[49m",
    "blackBG": "\u001b[40m\u001b[49m",
    "yellowBG": "\u001b[43m\u001b[49m",
    "redBG": "\u001b[41m\u001b[49m",
    "greenBG": "\u001b[42m\u001b[49m",
    "blueBG": "\u001b[44m\u001b[49m",
    "whiteBG": "\u001b[47m\u001b[49m",
    "cyanBG": "\u001b[46m\u001b[49m",
    "magentaBG": "\u001b[45m\u001b[49m",
    "rainbow": "",
    "zebra": "",
    "stripColors": "",
    "zalgo": ""
}

这是完整的错误:

{ 
"error": { 
    "code": "InvalidRequest", 
    "message": "Subscription validation request failed. Response must exactly match validationToken query parameter.",
    "innerError": { 
        "request-id": "08008b1b-4eda-4a09-a0d5-45ffcce1a8d6", 
        "date": "2018-08-26T02:43:08" 
    }
}
}
4

4 回答 4

4

Microsoft Graph 在创建订阅之前验证订阅请求的 notificationUrl 属性中提供的通知终结点。请参考以下链接:

https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks

Microsoft Graph WebHook:订阅验证令牌空白?

您可以像这样验证通知网址:

if (Request.QueryString["validationToken"] != null)
            {
                var token = Request.QueryString["validationToken"];
                return Content(token, "text/plain");
            }

https://github.com/microsoftgraph/aspnet-webhooks-rest-sample/blob/master/GraphWebhooks/Controllers/NotificationController.cs

于 2018-08-27T12:22:12.597 回答
1

Microsoft Graph API 询问了notificationUrl. 这里是调用订阅 API 时的 JSON

//POST https://graph.microsoft.com/v1.0/subscriptions    

{
           "changeType": "created,updated,deleted",
           "notificationUrl": "https://your_domain/outlook/ms_ping",
           "resource": "me/messages",
           "expirationDateTime":"2020-07-08T18:23:45.9356913Z",
           "clientState": "secretClientValue",
           "latestSupportedTlsVersion": "v1_2"
 }

一旦您调用 Microsoft 订阅 API,API 就会validationToken在您的notificationUrl. 您只需要使用validationToken您在 API 中的帖子正文中发送的 200 响应代码对此notificationUrl进行回复。所以这里是代码

//https://your_domain/outlook/ms_ping.php
    <?php
        $token = $_REQUEST['validationToken'];
        header("content-type:application/json");
        http_response_code(200);
        echo ($token);
    ?>
于 2020-07-06T13:21:26.577 回答
0

是在查询字符串上,而validationToken不是在请求的正文中。

于 2018-08-28T19:50:37.193 回答
0

您的通知端点似乎没有使用查询字符串中的验证令牌进行响应。响应应该只是纯文本的验证令牌。

不确定这是否是故意的,但您发送的请求的通知 url 与您在这篇文章中提到的通知 url 不匹配。

于 2018-08-29T21:22:34.647 回答