Discussions

Ask a Question
Back to all

Expired access token returns 403 instead of 401 – prevents automatic token refresh

Title: Expired access token returns 403 instead of 401 – prevents automatic token refresh

Hi Candis team,

we connect to the Candis API via n8n using the OAuth2 Authorization Code flow with the offline_access scope, with separate API credentials per organization.

After about 3 days (matching expires_in = 259200), our calls to
GET /v1/organizations/{organizationId}/invoices
fail with:
HTTP 403 – {"errorCode":"FORBIDDEN","message":"Access denied"}

After re-authorizing (new login), everything works again until the next expiry.

Our OAuth2 client refreshes the access token automatically, but only when the API responds with HTTP 401 (as per RFC 6750, "invalid_token"). Since the API returns 403, the refresh is never triggered and we have to reconnect manually every few days.

Questions:

  1. Does the API return 403 instead of 401 when the access token has expired?
  2. If so, could this be changed to 401 for expired/invalid tokens?
  3. Does the identity server (id.my.candis.io, userinfo endpoint) return 401 for an expired token? We'd use this as a workaround to trigger the refresh.
  4. Is the previous refresh token invalidated after a refresh (refresh token rotation)?

Thanks a lot!