【问题标题】:RightMove Datafeed API Auth - Axios TLS authRightMove 数据馈送 API 身份验证 - Axios TLS 身份验证
【发布时间】:2020-04-28 18:29:28
【问题描述】:

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

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

  • 文件.jks
  • 文件.p12
  • 文件.pem

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

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

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

【问题讨论】:

  • 您使用的是实时数据馈送吗? - 是否向您提供了任何文件?

标签: node.js api authentication axios api-auth


【解决方案1】:

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 })

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

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

【讨论】:

    【解决方案2】:

    所以我只使用 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 })
    

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 2016-04-12
      • 2016-04-24
      • 2020-04-19
      • 2016-07-09
      • 2018-11-12
      • 2013-05-25
      • 2015-02-02
      • 2018-02-24
      相关资源
      最近更新 更多