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

Abierto Apto para principiantes
#856 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript

Línea de trabajo

Empieza con getClientCredentialsToken() en src/XeroClient.ts e inspecciona cómo tokenRequest() codifica el cuerpo. Comprueba los ejemplos del README en las líneas 172 y 236 para localizar las indicaciones contradictorias. El trabajo estará terminado cuando la solicitud del token envíe los scopes solicitados como un parámetro scope separado por espacios y el comentario del README coincida con el comportamiento.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
264
Forks
177
Merge medio
10 h 5 min
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de XeroAPI/xero-node

Todos los issues de XeroAPI/xero-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.