xdmp http post 令牌认证选项
xdmp http post options for token authentication
我找到了 https://docs.marklogic.com/xdmp:http-post 函数。
我想使用令牌身份验证方法将 JSON 文档从 MarkLogic 发送到中间层 node.js 应用程序。我们使用令牌认证。
我应该使用什么 http 选项来完成这项工作?
示例:
(: Use xdmp:quote to encode the XML as a string
because the <data> options element is a string :)
let $payload := xdmp:quote('
{"alert": {
"id": "123abc",
"type": "sensorAlert",
"timestamp": "2015-08-12 T 13:48:45 CET",
"actions": ["go get them!"],
"status": "active"
}
}'
)
return
xdmp:http-post("http://cluey-app-ml1:9070/alert",
<options xmlns="xdmp:http">
<authentication method="basic">
<username>myname</username>
<password>mypassword</password>
</authentication>
<data>{$payload}</data>
<headers>
<content-type>application/json</content-type>
</headers>
</options>)
当然按原样发布会给我一个 401 未经授权的响应:
<response xmlns="xdmp:http">
<code>401</code>
<message>Unauthorized</message>
<headers>
<x-powered-by>Express</x-powered-by>
<access-control-allow-origin>*</access-control-allow-origin>
<content-type>text/html; charset=utf-8</content-type>
<content-length>26</content-length>
<etag>W/"1a-14Zh6wfLQpiHPatjrIEVAQ"</etag>
<set-cookie>connect.sid=s%3AT_lwAwvX9-1rJ7It7x42w126532HtIA2.nr5Zt2dONb6Q0uD7LpryZrpEsOUvXL8ZHUiTr8hOsfg; Path=/; HttpOnly</set-cookie>
<date>Tue, 08 Sep 2015 13:50:27 GMT</date>
<connection>keep-alive</connection>
</headers>
</response>
Text document
Could not broadcast alert.
虽然不是我所知道的 'feature',但可能没有什么能阻止您请求 "A" 来获取您的令牌,将其存储在 ML 中,然后通过设置将其用于后续请求您的令牌系统所需的适当header信息(例如Authentication:Bearerxxxxx)
令牌作为 header 信息发回。您可以在该页面上看到有关如何设置 header 信息的选项:https://docs.marklogic.com/xdmp:http-get
编辑如下以反映评论:
<headers>
<access-token>eyJ0eXAiO...RDHaNEjftfja-MofLqlv6fUKmN7k...</access-token>
<content-type>application/json</content-type>
</headers>
我找到了 https://docs.marklogic.com/xdmp:http-post 函数。
我想使用令牌身份验证方法将 JSON 文档从 MarkLogic 发送到中间层 node.js 应用程序。我们使用令牌认证。
我应该使用什么 http 选项来完成这项工作?
示例:
(: Use xdmp:quote to encode the XML as a string
because the <data> options element is a string :)
let $payload := xdmp:quote('
{"alert": {
"id": "123abc",
"type": "sensorAlert",
"timestamp": "2015-08-12 T 13:48:45 CET",
"actions": ["go get them!"],
"status": "active"
}
}'
)
return
xdmp:http-post("http://cluey-app-ml1:9070/alert",
<options xmlns="xdmp:http">
<authentication method="basic">
<username>myname</username>
<password>mypassword</password>
</authentication>
<data>{$payload}</data>
<headers>
<content-type>application/json</content-type>
</headers>
</options>)
当然按原样发布会给我一个 401 未经授权的响应:
<response xmlns="xdmp:http">
<code>401</code>
<message>Unauthorized</message>
<headers>
<x-powered-by>Express</x-powered-by>
<access-control-allow-origin>*</access-control-allow-origin>
<content-type>text/html; charset=utf-8</content-type>
<content-length>26</content-length>
<etag>W/"1a-14Zh6wfLQpiHPatjrIEVAQ"</etag>
<set-cookie>connect.sid=s%3AT_lwAwvX9-1rJ7It7x42w126532HtIA2.nr5Zt2dONb6Q0uD7LpryZrpEsOUvXL8ZHUiTr8hOsfg; Path=/; HttpOnly</set-cookie>
<date>Tue, 08 Sep 2015 13:50:27 GMT</date>
<connection>keep-alive</connection>
</headers>
</response>
Text document
Could not broadcast alert.
虽然不是我所知道的 'feature',但可能没有什么能阻止您请求 "A" 来获取您的令牌,将其存储在 ML 中,然后通过设置将其用于后续请求您的令牌系统所需的适当header信息(例如Authentication:Bearerxxxxx)
令牌作为 header 信息发回。您可以在该页面上看到有关如何设置 header 信息的选项:https://docs.marklogic.com/xdmp:http-get
编辑如下以反映评论:
<headers>
<access-token>eyJ0eXAiO...RDHaNEjftfja-MofLqlv6fUKmN7k...</access-token>
<content-type>application/json</content-type>
</headers>