You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用xero-node构建Xero客户端时触发“仅允许请求有效的绝对URL”错误的求助

xero-node构建Xero客户端时触发“仅允许请求有效的绝对URL”错误的求助

我在JavaScript开发中使用xero-node库,但创建Xero客户端并调用相关代码时遇到了一个棘手的问题,想请熟悉Xero的大佬帮忙分析一下。

我调用的核心代码是:

const consentUrl = await xero.buildConsentUrl()

创建Xero客户端的代码如下:

xero = new XeroClient({
  clientId: clientId,
  clientSecret: clientSecret,
  redirectUris: URL_REDIRECTS,
  scopes: ['openid', 'profile', 'projects']
  //state: 'not_currently_used', // 自定义参数(可选)
  //httpTimeout: 3000 // 毫秒(可选)
})

执行后直接抛出了以下错误:

index-C0C0EiKl.js:117 Uncaught (in promise) TypeError: only valid absolute URLs can be requested.

我查了调试日志,发现错误是在这段代码里触发的:

try {
  t = new DX1(e.url),  // 错误触发位置
    delete e.url,
    RX1(/^(https?:)$/.test(t.protocol))
} catch {
  throw new TypeError("only valid absolute URLs can be requested")
}

触发错误时,代码里的e.url是https://identity.xero.com/.well-known/openid-configuration。我特意在浏览器里访问了这个URL,明明能正常返回有效的配置数据,完全搞不懂为什么它会被判定为无效的URL。


补充信息

后来我暂时放弃了xero-node,改用原生的OAuth API调用来实现,这套流程能正常跑通,用到的URL如下:

const SCOPES = 'openid profile projects'
const URL_REDIRECT = 'http://localhost:5173/callback'
const STATE = 'mystate'
const XERO_URL_AUTH = `https://login.xero.com/identity/connect/authorize?response_type=code&client_id=${CLIENT_ID}&redirect_uri=${URL_REDIRECT}&scope=${SCOPES}&state=${STATE}`
const XERO_URL_TOKEN = 'https://identity.xero.com/connect/token'

在这套手动实现的流程里,完全没有用到那个出问题的https://identity.xero.com/.well-known/openid-configuration URL。我实在想不通xero-node到底做了什么特殊处理,才会导致请求这个URL时失败,会不会是我使用xero-node的方式有问题,触发了非标准的OAuth流程?

恳请各位大佬不吝赐教!

备注:内容来源于stack exchange,提问作者RodP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:08:01