调用Xero NodeJS OAuth2应用时Issuer.discover()失败求助
解决Xero Node.js OAuth2应用Issuer.discover()失败的问题
针对你遇到的AggregateError: Issuer.discover() failed错误(伴随301重定向和无返回体的OPError),可以尝试以下解决方法:
1. 更新xero-node依赖版本
Xero可能调整了OAuth端点的协议或配置,旧版依赖无法适配新的端点规则。执行命令更新到最新版:
npm update xero-node
2. 手动指定OAuth端点元数据,跳过自动发现
自动发现失败通常是因为库默认请求的端点返回301重定向,而旧版库不支持自动跟随重定向。初始化XeroClient时直接传入正确的HTTPS端点配置,绕过自动发现流程:
import { XeroClient } from 'xero-node'; const xero = new XeroClient({ clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, redirectUris: [process.env.REDIRECT_URI], scopes: ['openid', 'profile', 'email', 'accounting.transactions', 'offline_access'], // 手动指定Xero OAuth核心端点 issuer: 'https://identity.xero.com', jwksUri: 'https://identity.xero.com/.well-known/openid-configuration/jwks', authorizationUri: 'https://login.xero.com/identity/connect/authorize', tokenUri: 'https://identity.xero.com/connect/token', userInfoUri: 'https://api.xero.com/connect/userinfo' });
3. 排查网络/代理问题
确保开发环境能正常访问https://identity.xero.com和https://login.xero.com,若使用代理工具,检查是否拦截了OAuth相关请求导致重定向异常。
4. 确认Xero开发者后台配置
- 核对
REDIRECT_URI与代码中的配置完全一致(包括HTTP/HTTPS协议、端口号) - 确认
CLIENT_ID和CLIENT_SECRET属于状态正常的目标Xero应用,无权限或配置变更
内容的提问来源于stack exchange,提问作者Emiliano Giusto
相关产品推荐
相关产品推荐

