简体   繁体   English

Azure Microsoft Graph API - 订阅 - 验证请求失败

[英]Azure Microsoft Graph API - Subscription - validation request failed

I try to set up a notification for changes in Azure user data ( https://docs.microsoft.com/en-us/graph/webhooks ).我尝试为 Azure 用户数据的更改设置通知 ( https://docs.microsoft.com/en-us/graph/webhooks )。

I send a request from a local client to the Azure Graph API and I have a publicly available server (with SSL) in the payload of the request as notification URL.我从本地客户端向 Azure Graph API 发送请求,并且在请求的有效负载中有一个公开可用的服务器(带有 SSL)作为通知 URL。

Azure now sends a posts request to my server (like in the documentation - exact post request see below) and I try to send the token I got back (like in the documentation). Azure 现在向我的服务器发送一个帖子请求(就像在文档中一样 - 确切的帖子请求见下文),我尝试发送我得到的令牌(就像在文档中一样)。 But I always get the following error message "Subscription validation request failed. Response must exactly match validationToken query parameter."但我总是收到以下错误消息“订阅验证请求失败。响应必须与validationToken 查询参数完全匹配。”

Post request from Azure:来自 Azure 的发布请求:

Path: /?validationToken=Validation%3a+Testing+client+application+reachability+for+subscription+Request-Id%3a+3b3f9821-ce3f-23d9-879b-00a23f3 Body: is empty

I tried every part and encoding of the path (like just the request ID or the whole path) but I always get the error message.我尝试了路径的每个部分和编码(例如请求 ID 或整个路径),但我总是收到错误消息。 So whats the right thing to send back?那么什么是正确的送回去呢?

Firstly, the validation token you receive should be treated as an opaque value and returned unchanged and the error Subscription validation request failed. Response must exactly match validationToken query parameter首先,您收到的验证令牌应被视为不透明值并原样返回,并且错误Subscription validation request failed. Response must exactly match validationToken query parameter Subscription validation request failed. Response must exactly match validationToken query parameter is trying to tell you that something changed. Subscription validation request failed. Response must exactly match validationToken query parameter试图告诉您某些内容发生了变化。

Since the validation token comes to you as a URL query parameter, make sure you're working with a properly decoded value in your code before returning it .由于验证令牌是作为 URL 查询参数提供给您的,因此请确保在返回之前在代码中使用正确解码的值

Here is the relevant documentation from Microsoft Docs: Notification endpoint validation以下是 Microsoft Docs 的相关文档: 通知端点验证

POST https://{notificationUrl}?validationToken={opaqueTokenCreatedByMicrosoftGraph}

在此处输入图片说明

Other requirements(from the same reference):其他要求(来自同一个参考):

  • response within 10 seconds 10秒内响应
  • 200 (OK) status code. 200(正常)状态代码。
  • content type must be text/plain.内容类型必须是文本/纯文本。
  • body must include the validation token.正文必须包含验证令牌。

Code Samples代码示例

ASP.NET MVC Sample - Specifically look at the NotificationController.cs file ASP.NET MVC 示例- 具体看 NotificationController.cs 文件

    [HttpPost]
    public async Task<ActionResult> Listen()
    {

        // Validate the new subscription by sending the token back to Microsoft Graph.
        // This response is required for each subscription.
        if (Request.QueryString["validationToken"] != null)
        {
            var token = Request.QueryString["validationToken"];
            return Content(token, "plain/text");
        }

Node.js code sample - Specifically look at listen.js Node.js 代码示例——具体看listen.js

/* Default listen route */
listenRouter.post('/', (req, res, next) => {
  let status;
  let clientStatesValid;

  // If there's a validationToken parameter in the query string,
  // then this is the request that Office 365 sends to check
  // that this is a valid endpoint.
  // Just send the validationToken back.
  if (req.query && req.query.validationToken) {
    res.send(req.query.validationToken);
    // Send a status of 'Ok'
    status = 200;
  }

You should return the validationToken from the query string with an HTTP 200 response code.您应该从带有HTTP 200响应代码的查询字符串中返回validationToken You also have to do that within a few seconds, or the graph will fail the request and your call to create the subscription will fail.您还必须在几秒钟内执行此操作,否则图形将无法请求,并且您创建订阅的调用将失败。

Here is an example of the validation endpoint in ASP.NET Web API 2:以下是 ASP.NET Web API 2 中验证端点的示例:

public ActionResult<string> Post([FromQuery]string validationToken = null)
{
    if(!string.IsNullOrEmpty(validationToken))
    {
        Console.WriteLine($"Token: '{validationToken}'");
        return Ok(validationToken);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用自定义 Api 作为通知侦听器的验证请求上的 Microsoft Azure Graph API 订阅错误 - Microsoft Azure Graph API Subscription Errors on Validation request using Custom Api as Listener for notifications IDX10503:Microsoft Graph和Azure AD的签名验证失败 - IDX10503: Signature validation failed with Microsoft Graph and Azure AD Microsoft Graph API问题iOS:无法完成请求验证错误 - Microsoft Graph API Problems iOS : Unable to Complete Request Validation Error Microsoft Graph 订阅限制 - Microsoft Graph Subscription Limitations Microsoft Graph API 是否适用于 Office 365 家庭版订阅? - Does Microsoft Graph API work with Office 365 family subscription? 在 Microsoft ToDo 任务中获取禁止错误创建订阅图 API - Getting Forbidden Error in Microsoft ToDo Tasks create subscription Graph API Microsoft Azure订阅 - Microsoft Azure Subscription Powershell 使用 Microsoft Graph 创建 Azure 用户 API - Powershell Create Azure user with Microsoft Graph API 从Azure Functions调用Microsoft Graph API - Calling Microsoft Graph API from Azure Functions Microsoft Graph API - 权限不足,Request_ResourceNotFound - Azure 权限问题 - Microsoft Graph API -Insufficient privileges, Request_ResourceNotFound - Azure Permissions Issues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM