Describe the problem/error/question
Hi,
I’m building a custom n8n node for an API whose authorization flow is a bit different from standard OAuth2.
The process is:
-
Send a request to a dedicated endpoint to obtain an API key.
-
The endpoint responds with JSON like:
{ "response": { "api_key": "<string>", "expires_in": "<timestamp>" }, "status": { "code": 200 } } -
The
api_keyis valid for 10 days and must be used to access all API endpoints.
I could simply request a new key every time before calling the API resources, but that seems inefficient.
What is the recommended way to implement authentication in a custom n8n node so that:
-
The API key and its expiry timestamp are stored,
-
The node checks whether the key is still valid on each execution,
-
and, only if the key has expired, it requests a new one?
Any best practices or example patterns for handling this “long-lived key with auto-refresh” inside an n8n custom node would be appreciated.
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system: