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

オープン 初心者向け
#856 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript

調査の方向性

src/XeroClient.ts の getClientCredentialsToken() から始め、tokenRequest() が本文をどのようにエンコードするかを確認してください。README の172行目と236行目の例を確認し、説明に矛盾がないか調べてください。トークンリクエストが要求されたスコープをスペース区切りの 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分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

XeroAPI/xero-node のほかの issue

XeroAPI/xero-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。