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

Aperta Adatta ai principianti
#856 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript

Direzione di ricerca

Inizia con getClientCredentialsToken() in src/XeroClient.ts e controlla come tokenRequest() codifica il corpo. Verifica gli esempi del README alle righe 172 e 236 per individuare le indicazioni in conflitto. Il lavoro è completato quando la richiesta del token invia gli scope richiesti come parametro scope separato da spazi e il commento del README corrisponde al comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
264
Fork
177
Merge medio
10h 5m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di XeroAPI/xero-node

Tutte le issue di XeroAPI/xero-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.