RightMove Datafeed API 验证 - Axios TLS 验证

RightMove Datafeed API Auth - Axios TLS auth

我正在开发一个模块,需要我使用他们的 API 将数据输入 RightMove。但在此之前,它需要相互认证来验证数据馈送器——它使用一些证书和密钥。

我从 RightMove 收到了以下文件格式:

我还有一个由 RightMove 提供的用于这些(或其中一个)文件的密码。

现在我必须使用这些文件通过 RightMove 进行身份验证,但我不确定哪个文件能做什么。我在 Node.js

中使用 Axios

有人可以帮我形成一个 axios 调用,使用这些文件进行身份验证吗?

https://media.rightmove.co.uk/ps/pdf/guides/adf/Rightmove_Real_Time_Datafeed_Specification.pdf

所以我查看了 RightMove API 的文档,它在第 5 页上说它们根据开发环境为您提供了所有三个文件。

为此,我们将使用 .pem 文件。

const https = require('https')
const fs = require('fs')
const axios = require('axios')

const key = fs.readFileSync('./key.pem')
const ca = fs.readFileSync('./ca.crt')

const url = 'https://adfapi.rightmove.co.uk/'

const httpsAgent = new https.Agent({
    rejectUnauthorized: true, // Set to false if you dont have the CA
    key,
    ca,
    passphrase: 'YYY', // Would recommend storing as secret
    keepAlive: false,
})

const axiosInstance = axios.create({ headers: { 'User-Agent': 'rightmove-datafeed/1.0' }, httpsAgent })

axiosInstance.get(url, { httpsAgent })

我注意到文档说一些 API 与 RightMove 一起使用,您需要设置自定义 User-Agent。文档提到他们有 JSON 或 XML 模式可供下载 here。您还可以查看示例回复。

因为您很可能会进行多次调用,所以我创建了一个 axios 实例,这意味着您只需为所有请求设置一次这些选项。

所以我只使用 p12 文件和密码解决了它。不需要 JKS 文件和 PEM 文件。

const httpsAgent = new https.Agent({
   pfx: fs.readFileSync('/path/to/p12/file'),
   passphrase: '<your-passphrase>',
})
await axios.post(url, data, { headers, httpsAgent })