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).
- Sign in to the Xero developer portal and open My Apps; click New app.
- 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.
- Add your callback URL to the app’s OAuth 2.0 redirect URIs. It must be an
https://address;http://localhostis allowed for testing buthttp://127.0.0.1is not. - Save the app, then copy the Client id from the Configuration tab and generate a Client secret (shown once — store it securely).
- Decide the minimum scopes you need. Always include
offline_accessto 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). - Send the user to
https://login.xero.com/identity/connect/authorizewithresponse_type=code, yourclient_id,redirect_uri, a space-separatedscope, and a uniquestate. The user picks which organisation(s) to connect. - On success Xero redirects back with a
code(single-use, expires 5 minutes) and yourstate. Exchange the code athttps://identity.xero.com/connect/tokenviaPOSTwithContent-Type: application/x-www-form-urlencoded, sendinggrant_type=authorization_code,code,redirect_uri, and anAuthorization: Basic base64(client_id:client_secret)header. - The token response returns
access_token(30-minute lifetime),refresh_token(present only whenoffline_accesswas requested; 60-day lifetime),expires_in,token_type, andid_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/connectionswith the access token to list connected tenants and read eachtenantId. Send that value as thexero-tenant-idheader on every core API call (alongsideAuthorization: Bearer {access_token}). FilterGET /connections?authEventId=...using theauthentication_event_idclaim 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_tokenat the same token endpoint) returns a newaccess_tokenand a newrefresh_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 inX-Rate-Limit-Problemand givesRetry-Afterseconds.
Connect it to Publicus
Section titled “Connect it to Publicus”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.