Zum Inhalt springen

Lektion 11 · APIs and Integrations

Credentials and Authentication

Store secrets safely in n8n credentials, compare API keys, header auth and OAuth, limit permissions, share carefully, rotate keys and protect the encryption key.

Almost every integration needs proof of who you are. n8n keeps that proof in credentials: separate, named records that nodes use. The secrets are stored encrypted, and workflows only refer to them. That separation lets you share or export a workflow without copying the keys into its steps.

Common authentication styles

Style How it works Notes
API key A secret string sent in a header or query Simple; protect it well
Basic auth Username and password Only over HTTPS
Header auth A custom header name and value Common for private APIs
Bearer token Authorization: Bearer <token> Often expires
OAuth 2.0 You grant access on the provider's page Limited scopes, refreshable

For popular services, n8n has dedicated credential types that fill in the details. The HTTP Request node can often reuse them through its predefined credential option. For other APIs, choose a generic type such as header auth.

How OAuth feels

sequenceDiagram
  participant You
  participant N as n8n
  participant P as Provider
  You->>N: Connect account
  N->>P: Send you to sign in
  You->>P: Approve requested access
  P-->>N: Return a code
  N->>P: Exchange code for tokens

You sign in on the provider's own page, and n8n receives tokens, not your password.

You usually create an app in the provider's developer console and copy a client ID and secret into n8n, plus register n8n's redirect URL with the provider. If the redirect URL does not match exactly, sign-in fails. Review the scopes the app requests and grant only what the workflow needs.

Least privilege

Give every credential the smallest power that works:

  • Use a dedicated account or service user, not your personal admin login.
  • Prefer read-only keys for workflows that only read.
  • Use test or sandbox keys while building.
  • Use separate credentials for development and production.

Do not leak secrets

Even with credentials, secrets can escape:

  • pasting a key into a node parameter, sticky note or code;
  • logging full request headers;
  • putting tokens in a URL, where servers often record them;
  • sharing screenshots or exports that include data from runs.

If a secret leaks, revoke and replace it at the provider. Deleting the message is not enough.

Python Stand-in: mask secrets before logging

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The encryption key

Self-hosted n8n encrypts credentials with an encryption key. If you do not set one, n8n generates it on first start and saves it in its data folder. You can set it yourself with the N8N_ENCRYPTION_KEY environment variable.

If you lose the key, a restored database cannot decrypt your credentials. Back up the key separately and securely. Workers in queue mode need the same key as the main instance.

Newer versions add key rotation. In 3.0 it is on by default. Enabling it is a one-way change, so read the rotation documentation and take a full backup before upgrading or turning it on.

Sharing and access

In team setups you can give other users access to workflows and credentials. As of December 2026, the documentation lists sharing for all n8n Cloud plans and, when self-hosting, only for Business and Enterprise plans. Someone who can use a credential in a workflow may be able to make the connected service act on its behalf, even without seeing the raw secret. Review who has access, and remove people when they leave. Some enterprise plans can fetch secrets from an external secrets manager.

Rotation checklist

  1. Create the new key at the provider.
  2. Update the n8n credential.
  3. Run a safe test.
  4. Revoke the old key.
  5. Note the date and who did it.
JS Stand-in: find credentials due for rotation

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The 180-day limit here is only an example. Follow your organization's policy and the provider's advice.

When authentication fails

A 401 usually means the key is missing, wrong or expired. A 403 usually means you are known but not allowed, often because of a missing scope or role. For OAuth, reconnect the credential and check the redirect URL and approved scopes. Check the environment too, since a test key sent to a production address will be rejected. Never fix a 403 by granting full admin rights without understanding which permission is missing.

Practice

Make a small inventory for an imaginary workflow that reads from a spreadsheet, calls a CRM and posts to chat. For each connection, note the authentication style, the account that owns the credential, the minimum permissions it needs, where the secret can be revoked and who should be told if it leaks. You will often find that one broad personal account is doing everything. Replace it with narrower service accounts where the provider supports them. Keep the inventory without any secret values, so you can safely share it with your team and review it later.

Check your understanding

Quick check · 3 questions

of 3 answered You scored / 3 · perfect!

  1. 1. Why store secrets in credentials rather than node text?

    Credentials separate secrets from workflow logic.
  2. 2. A key was pasted into a shared screenshot. What should you do?

    Assume a leaked key is compromised.
  3. 3. What happens if you restore a database but lose the encryption key?

    The key is required to decrypt them.

Summary

  • Credentials keep secrets apart from workflow steps.
  • OAuth grants limited access without sharing your password.
  • Use least privilege, separate environments and rotate keys.
  • Back up the encryption key and treat leaks as compromises.

Next: Pagination and Rate Limits

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.