Skip to content
Docs

Creating a Xero OAuth 2.0 app (authorization code)

This guide is part of the Publicus connection catalog. Once you have the credentials, connect the service and Publicus stores them for you.

Distilled from Xero’s own documentation: The standard authorization code flow, Scopes, and OAuth 2.0 API limits. Retrieved 2026-07-03.

Use this flow for web-server apps that can keep a client secret. Native/mobile apps with no secret should use Xero’s PKCE flow instead (same endpoints, public client, PKCE required).

  1. Sign in to the Xero developer portal and open My Apps; click New app.
  2. Choose Auth Code (a.k.a. “Web app”) as the integration type — this selects the authorization-code grant. Give the app a name and company URL.
  3. Add your callback URL to the app’s OAuth 2.0 redirect URIs. It must be an https:// address; http://localhost is allowed for testing but http://127.0.0.1 is not.
  4. Save the app, then copy the Client id from the Configuration tab and generate a Client secret (shown once — store it securely).
  5. Decide the minimum scopes you need. Always include offline_access to receive a refresh token, plus the OpenID Connect scopes (openid profile email) if you need user identity, and the accounting scopes for the capabilities you use (e.g. accounting.invoices accounting.contacts.read).
  6. Send the user to https://login.xero.com/identity/connect/authorize with response_type=code, your client_id, redirect_uri, a space-separated scope, and a unique state. The user picks which organisation(s) to connect.
  7. On success Xero redirects back with a code (single-use, expires 5 minutes) and your state. Exchange the code at https://identity.xero.com/connect/token via POST with Content-Type: application/x-www-form-urlencoded, sending grant_type=authorization_code, code, redirect_uri, and an Authorization: Basic base64(client_id:client_secret) header.
  8. The token response returns access_token (30-minute lifetime), refresh_token (present only when offline_access was requested; 60-day lifetime), expires_in, token_type, and id_token (only with OIDC scopes).

Operational notes (from developer.xero.com/documentation/guides/oauth2/auth-flow):

  • Discover the tenant. The token response contains no organisation id. Call GET https://api.xero.com/connections with the access token to list connected tenants and read each tenantId. Send that value as the xero-tenant-id header on every core API call (alongside Authorization: Bearer {access_token}). Filter GET /connections?authEventId=... using the authentication_event_id claim in the decoded access-token JWT to isolate the tenants authorised in this flow.
  • Refresh tokens rotate and are single-use. Every refresh (grant_type=refresh_token at the same token endpoint) returns a new access_token and a new refresh_token; you must persist both. The previous refresh token is superseded, but there is a 30-minute grace window to retry with the previous refresh token if you failed to save the new one. After 30 minutes the old token is invalid and the user must re-authorise. Refresh tokens otherwise expire after 60 days of non-use.
  • Reducing scope means starting over. Scopes cannot be removed from an existing token; requesting the user through the flow again only adds scopes. To narrow access, revoke the refresh token (POST https://identity.xero.com/connect/revocation) and reconnect.
  • Connection caps. Starter-tier apps allow 5 connections (uncertified apps historically capped at 25 tenants); each organisation may connect at most two uncertified apps. Become an app partner to raise the limits.
  • Rate limits (from OAuth 2.0 API limits). Per tenant: 60 calls/minute, 5 concurrent, and a daily cap of 1,000 calls/day on the Starter tier or 5,000 calls/day on the Core tier and above; app-wide 10,000 calls/minute. The 1,000-vs-5,000 daily split is driven by your app’s app-partner-program tier (Starter / Core / Plus / Advanced) — new/uncertified apps default to the Starter tier and moving the app up to Core or above raises the cap — not by the connected organisation’s Xero subscription plan. Watch X-DayLimit-Remaining, X-MinLimit-Remaining, X-AppMinLimit-Remaining; a 429 names the limit in X-Rate-Limit-Problem and gives Retry-After seconds.

Open Connections under Credentials, choose Xero, and pick Xero OAuth 2.0 (authorization code). Publicus asks for exactly the fields listed above and keeps them in your workspace’s secret storage.

See also: Xero in the catalog.

This guide is maintained by Publicus and published under CC BY 4.0.