← statichum.studio

Proactive, expiry-based OAuth2 token refresh for automation tools (handle APIs that return HTTP 200 with an error body)

dev tool weekend hack •• multiple requests

n8n's generic OAuth2 only refreshes a token reactively when an API returns HTTP 401, but services like Adobe Marketo return HTTP 200 with the error inside the response body, so the token silently goes stale and the integration breaks. Multiple builders independently want refresh driven by the token's own expires_in value inside the credential boundary, rather than trusting status codes.

builder note

The non-obvious bug is that 'token expired' is not the same as 'HTTP 401' for a meaningful set of enterprise APIs; refresh proactively off the token's expires_in (with a safety margin) instead of trusting the status code, and you fix a whole class of silent integration failures that status-code-based refresh can never catch.

landscape (2 existing solutions)

Automation tools assume an expired token surfaces as HTTP 401, but real-world APIs (Marketo and friends) return 200 with an error in the body, so refresh-on-401 fails silently. The unmet need is proactive refresh based on expires_in inside the credential, and n8n's maintainers closed the escalation as working-as-expected, leaving the demand open.

n8n generic OAuth2 credential Refreshes tokens only reactively on an HTTP 401, so any API that signals expiry via a 200-with-error-body silently keeps using a dead token until the workflow fails.
Hand-rolled HTTP Request node workaround Forces builders to re-implement OAuth2 refresh logic in plain HTTP nodes per integration, losing the convenience and security of the managed credential.

sources (1)

other https://community.n8n.io/t/generic-oauth2-authentication-enf... "Some APIs return HTTP 200 with error messages in the response body instead of standard error codes" 2026-06-11
workflow-automationoauth2n8napi-integrationtokens