Skip to content

fix: fallback to V2 granular scopes on 401/403 as well as invalid_scope#177

Open
ErnestHysa wants to merge 2 commits into
XeroAPI:mainfrom
ErnestHysa:fix/v1-deprecated-scopes
Open

fix: fallback to V2 granular scopes on 401/403 as well as invalid_scope#177
ErnestHysa wants to merge 2 commits into
XeroAPI:mainfrom
ErnestHysa:fix/v1-deprecated-scopes

Conversation

@ErnestHysa

Copy link
Copy Markdown

Problem

New Custom Connections created after the April 2025 deprecation of accounting.transactions fail authentication because the server returns 401 or 403 instead of 400 invalid_scope.

The xero-client only falls back from V1 (deprecated accounting.transactions) to V2 (granular) scopes on an invalid_scope error, but new connections using deprecated V1 scopes receive 401/403 instead.

Fix

Extend the V1→V2 fallback condition to also trigger on 401 and 403 responses, not just on 400 invalid_scope.

const isCredentialError =
  axiosError.response?.status === 401 ||
  axiosError.response?.status === 403;

if (!isInvalidScope && !isCredentialError) {
  throw this.formatTokenError(error, " with V1 scopes");
}

Closes #175

Previously the xero-client only fell back from V1 to V2 scopes on an
'invalid_scope' (400) error. New Custom Connections created after the
April 2025 deprecation of accounting.transactions return 401 or 403
instead of 400, causing them to fail without this fix.

Closes XeroAPI#175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom Connections created after 29 April 2026 fail with "Client credentials scope validation failed" due to deprecated hardcoded scopes

1 participant