`getClientCredentialsToken()` sends `scopes` (comma-joined) instead of the OAuth `scope` parameter

未关闭 适合新手
#856 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

从 src/XeroClient.ts 中的 getClientCredentialsToken() 开始,检查 tokenRequest() 如何对请求体进行编码。查看 README 第 172 行和第 236 行的示例,找出相互冲突的说明。完成标准是:令牌请求将所请求的 scope 作为以空格分隔的 scope 参数发送,并且 README 注释与该行为一致。

由索引模型根据 Issue 内容生成。

描述

Which version of the SDK are you using?

20.3.0 (master at 538aa65)

Summary

getClientCredentialsToken() passes the configured scopes to the token endpoint under the key scopes:

https://github.com/XeroAPI/xero-node/blob/538aa65/src/XeroClient.ts#L196-L198

const { clientId, clientSecret, grantType, scopes } = this.config;
const result = await this.tokenRequest(clientId, clientSecret, { grant_type: grantType, scopes });

encodeBody() then runs encodeURIComponent on the array, which joins it with commas. The request body is:

POST https://identity.xero.com/connect/token
grant_type=client_credentials&scopes=accounting.transactions%2Caccounting.contacts

(captured by stubbing axios and calling getClientCredentialsToken() with scopes: ['accounting.transactions', 'accounting.contacts'])

The token endpoint expects the standard scope parameter, space-delimited (RFC 6749 §4.4.2). scopes isn't a token request parameter, so the requested scopes are not actually requested and the token falls back to whatever the connection grants by default. That breaks the README example that relies on requesting marketplace.billing for App Store calls (README L172). It also means an app can't narrow a custom-connection token to fewer scopes.

xero-python already does this correctly (post_data["scope"] = "marketplace.billing").

Suggested fix
const body: Record<string, string> = { grant_type: grantType };
if (scopes?.length) body.scope = scopes.join(' ');
const result = await this.tokenRequest(clientId, clientSecret, body);

The README comment at L236 (scopes ... // not used for client_credentials auth flow) contradicts L172 and could be updated at the same time.

主要语言
TypeScript
星标
264
派生
177
平均合并
10 小时 5 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

XeroAPI/xero-node 的其他 Issue

查看 XeroAPI/xero-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。