Single Sign-On (SSO)
Relevant source files
The following files were used as context for generating this wiki page:
- packages/cli/src/sso.ee/saml/saml.service.ee.ts
- packages/cli/src/sso.ee/oidc/oidc.service.ee.ts
- packages/cli/src/sso.ee/saml/routes/saml.controller.ee.ts
- packages/@n8n/config/src/configs/sso.config.ts
- packages/frontend/editor-ui/src/constants.ts
- packages/cli/src/sso.ee/oidc/routes/oidc.controller.ee.ts
- packages/cli/src/sso.ee/sso.service.ts
Single Sign-On (SSO) in n8n is an enterprise feature that allows users to authenticate using third-party Identity Providers (IdPs). This centralizes user authentication, enhances security, and simplifies user management for organizations. n8n supports two primary SSO protocols: Security Assertion Markup Language (SAML) and OpenID Connect (OIDC).
The implementation is designed to be modular, with separate services and controllers for each protocol. When a user attempts to log in via SSO, n8n redirects them to the configured IdP. After successful authentication, the IdP sends an assertion (for SAML) or an ID token (for OIDC) back to n8n. n8n then validates this response, and either logs in the existing user or provisions a new user account based on the information received from the IdP.
Configuration
SSO functionality is configured through environment variables. The system checks these variables to enable and configure the SAML or OIDC protocols.
Sources: packages/@n8n/config/src/configs/sso.config.ts
| Variable | Type | Description |
|---|---|---|
N8N_SSO_SAML_ENABLED | boolean | Enables or disables SAML-based SSO. |
N8N_SSO_SAML_ENTRY_POINT | string | The IdP's single sign-on URL. |
N8N_SSO_SAML_IDP_CERT | string | The IdP's x509 certificate. |
N8N_SSO_SAML_ISSUER | string | The issuer URL for the n8n service provider. |
N8N_SSO_SAML_EMAIL_ATTRIBUTE | string | The attribute name in the SAML assertion for the user's email. Defaults to email. |
N8N_SSO_SAML_FIRST_NAME_ATTRIBUTE | string | The attribute name for the user's first name. Defaults to firstName. |
N8N_SSO_SAML_LAST_NAME_ATTRIBUTE | string | The attribute name for the user's last name. Defaults to lastName. |
N8N_SSO_OIDC_ENABLED | boolean | Enables or disables OIDC-based SSO. |
N8N_SSO_OIDC_AUTHORIZATION_URL | string | The OIDC provider's authorization endpoint URL. |
N8N_SSO_OIDC_CLIENT_ID | string | The client ID for the n8n application registered with the OIDC provider. |
N8N_SSO_OIDC_CLIENT_SECRET | string | The client secret for the n8n application. |
N8N_SSO_OIDC_ISSUER | string | The issuer URL of the OIDC provider. |
N8N_SSO_OIDC_TOKEN_URL | string | The OIDC provider's token endpoint URL. |
N8N_SSO_OIDC_USER_INFO_URL | string | The OIDC provider's userinfo endpoint URL. |
N8N_SSO_OIDC_SCOPE | string | The OIDC scopes to request. Defaults to openid profile email. |
N8N_SSO_OIDC_EMAIL_ATTRIBUTE | string | The attribute name in the OIDC claims for the user's email. Defaults to email. |
N8N_SSO_OIDC_FIRST_NAME_ATTRIBUTE | string | The attribute name for the user's first name. Defaults to given_name. |
N8N_SSO_OIDC_LAST_NAME_ATTRIBUTE | string | The attribute name for the user's last name. Defaults to family_name. |
N8N_SSO_LOGIN_METHOD | string | Defines the default SSO login method. Can be saml or oidc. |
Architecture
The SSO system is built upon a main SsoService that delegates to protocol-specific services (SamlService and OidcService). Each protocol has a dedicated controller to handle HTTP requests for the authentication flow.
This diagram illustrates the high-level component relationships within the SSO module.
SAML Authentication
The SAML flow is initiated when a user navigates to the SAML login endpoint. n8n acts as the Service Provider (SP) and redirects the user to the configured Identity Provider (IdP) for authentication.
Sources: packages/cli/src/sso.ee/saml/routes/saml.controller.ee.ts, packages/cli/src/sso.ee/saml/saml.service.ee.ts
SAML Endpoints
| Method | Path | Description |
|---|---|---|
GET | /saml/login | Initiates the SAML login process by redirecting the user to the IdP. |
POST | /saml/acs | Assertion Consumer Service (ACS). The IdP POSTs the SAML assertion to this endpoint after successful user authentication. |
GET | /saml/metadata | Provides the Service Provider metadata XML for configuring the IdP. |
SAML Login Flow
The following sequence diagram shows the SAML authentication process.
OIDC Authentication
The OpenID Connect (OIDC) flow is similar to SAML but uses OAuth 2.0 tokens. When a user initiates an OIDC login, they are redirected to the OIDC provider's authorization endpoint.
Sources: packages/cli/src/sso.ee/oidc/routes/oidc.controller.ee.ts, packages/cli/src/sso.ee/oidc/oidc.service.ee.ts
OIDC Endpoints
| Method | Path | Description |
|---|---|---|
GET | /oidc/login | Initiates the OIDC login process by redirecting the user to the provider's authorization endpoint. |
GET | /oidc/callback | The OIDC provider redirects the user back to this endpoint with an authorization code. n8n exchanges the code for tokens. |
OIDC Login Flow
This diagram illustrates the OIDC authentication code flow.
User Provisioning
Upon successful authentication via SAML or OIDC, n8n receives a user profile. The SsoService handles user provisioning with the findOrCreateUser method.
- It extracts the user's email, first name, and last name from the IdP's response, based on the configured attribute mappings.
- It attempts to find an existing n8n user with the provided email address.
- If a user is found, they are logged in.
- If no user is found, a new user account is created (just-in-time provisioning) with the details from the IdP. The user's password is set to a long, random, and unusable string, as authentication is managed by the IdP.
Sources: packages/cli/src/sso.ee/sso.service.ts:35-61, packages/cli/src/sso.ee/saml/saml.service.ee.ts:84-89, packages/cli/src/sso.ee/oidc/oidc.service.ee.ts:105-110
Frontend Integration
The frontend UI provides views for managing SSO settings. The constants.ts file defines keys for these views and related enums.
VIEWS.SSO_SETTINGS: A constant representing the SSO settings view in the UI, where administrators can configure SAML and OIDC.VIEWS.SAML_ONBOARDING: A constant for the SAML onboarding view.SignInTypeEnum: This enum includesoidcas a sign-in type, used by the frontend to differentiate login methods.
These constants link the backend SSO logic to the user interface components for a seamless configuration experience.
Sources: packages/frontend/editor-ui/src/constants.ts:553, packages/frontend/editor-ui/src/constants.ts:555, packages/frontend/editor-ui/src/constants.ts:701-705