Introducing a new way to review your PRs.

Read the announcement

elsa-workflows / elsa-core

The Workflow Engine for .NET

View on GitHub

32 documents · Updated Oct 7, 2026

docs / external-authentication

External authentication

External authentication connects Elsa users to identity providers outside Elsa. It presents trusted login methods, runs a protected sign-in flow, maps the returned external identity to an Elsa user, and issues Elsa tokens for the selected tenant. The domain also gives deployments controlled sources for provider connections, secrets, and durable authentication state. See the security and multitenancy page for the wider security model, secrets, tenants, and identity for related identity boundaries, and EF Core persistence providers for the shared database model.

System role

Service foundation

The external authentication service foundation provides the protocol-neutral broker, connection registry, identity policies, permission grant sources, security controls, and process-local state needed for a single Elsa node. Hosts can replace the process-local stores with durable stores when several nodes must share authentication progress or sessions. The foundation also registers the module’s authorization resources, rate limits, data protection, tenant access, and optional health check. src/…/ServiceCollectionExtensions.cs defines this default service boundary.

References: src/…/ServiceCollectionExtensions.cs• L22-30 src/…/ServiceCollectionExtensions.cs• L36-60 src/…/ServiceCollectionExtensions.cs• L62-117

Brokered identity flow

The external authentication broker is the boundary between an Elsa client, an external identity provider, and Elsa identity services. A registered authentication client starts the flow for a selected connection. After the provider confirms the user, Elsa resolves the external identity, applies permission rules, creates a session, and returns a short-lived authorization result that the client exchanges for Elsa tokens.

The main flow moves through these stages:

sequenceDiagram
    participant Client as Elsa client
    participant Broker as Elsa authentication broker
    participant Provider as External identity provider
    participant Identity as Elsa identity services
    participant Session as Authentication session store

    Client->>Broker: Discover login methods
    Client->>Broker: Start authorization with connection
    Broker->>Provider: Authorization request with state, nonce, and S256 PKCE
    Provider-->>Broker: Authorization callback with code
    Broker->>Provider: Exchange code and validate ID token
    Provider-->>Broker: Trusted external identity and claims
    Broker->>Identity: Resolve user and external identity link
    Broker->>Identity: Resolve Elsa permission grants
    Broker->>Session: Save external session
    Broker-->>Client: One-time authorization code
    Client->>Broker: Exchange code or refresh token
    Broker-->>Client: Elsa access and refresh tokens

The broker keeps the provider transaction separate from the Elsa session. This lets callback state expire quickly while the resulting session has its own lifetime and can be revoked without repeating provider sign-in.

References: src/…/ExternalAuthenticationBroker.cs• L68-163 src/…/ExternalAuthenticationBroker.cs• L165-267 src/…/ExternalAuthenticationBroker.cs• L304-394 src/…/ExternalAuthenticationContracts.cs• L254-258

Connection registry

An identity provider connection is Elsa’s named description of one upstream login method. It joins an adapter type with provider settings, secret bindings, display data, claim rules, identity-link policy, permission grant sources, and logout behavior.

The effective connection registry combines deployment configuration with an optional database source. The current registry builds the host-scope connection set used by authentication requests and management. It marks conflicts or superseded entries, checks whether the adapter and its secrets are usable, and then advertises only valid enabled methods to the broker.

Connection management uses the connection revision as an optimistic concurrency check. Responses expose the revision as an ETag, and mutation requests must send the matching If-Match value. Configuration-owned connections remain read-only through this management surface. Database-owned connections can be changed only when the caller has the required permission, and policy, grant, session-revocation, and provider-trust changes receive extra permission checks.

Connection concernPurpose
Adapter type and settingsSelects the protocol handler and its provider trust data
Scope and keyPlaces the method in the host or tenant connection space
LifecycleControls whether a method is a draft, disabled, enabled, or archived
Claim projectionLimits which provider claims enter Elsa processing
Identity policyDecides how an external identity without a link is handled
Permission sourcesDefines which Elsa permissions the connection may add

Configuration-owned connections are deployment controlled. Database-owned connections support managed administration when that source is enabled. A database connection can explicitly override a configuration connection only when deployment policy allows it.

References: src/…/ExternalAuthenticationModels.cs• L5-31 src/…/DefaultIdentityProviderConnectionRegistry.cs• L18-85 src/…/ConfigurationIdentityProviderConnectionSource.cs• L23-72 src/…/DatabaseIdentityProviderConnectionSource.cs• L21-29 src/…/IdentityProviderConnectionValidityAssessor.cs• L19-83 src/…/ConnectionEndpointSupport.cs• L9-54

After a provider authenticates a subject, Elsa identifies the external identity by its issuer and subject. An external identity link binds that identity to one Elsa user within one tenant and one connection key. The default policy rejects an identity with no link. A deployment may allow just-in-time creation of a credential-less Elsa user or use a trusted matcher to link an existing user.

The resolver first looks for an existing link. If it finds none, an unlinked identity policy chooses whether to reject the sign-in, create a credential-less user, or link an existing user selected by a trusted matcher. The provisioning service checks that a selected user belongs to the target tenant and can assign configured default roles to a new user. Concurrent requests converge on one link for the same external identity tuple.

Administrators can prelink an external identity to an existing user, replace a link, or unlink it. These operations are tenant-bounded and permission guarded. They use the same link invariant as sign-in provisioning, so a manual link cannot silently take an identity already linked to another user.

Role deletion also considers external authentication policies that assign default roles during just-in-time provisioning. Elsa inspects configuration and stored connections in the role’s tenant scope, blocks unsafe removal, or replaces the last default role only after the actor is authorized to assign the replacement. This keeps role deletion from leaving a provisioning policy with an invalid or cross-tenant role reference.

The connection can also project selected claims and turn approved provider data into Elsa permission grants. Deployment-wide allow and deny boundaries still apply after grant sources produce candidates, so a provider connection cannot grant a permission that the deployment does not permit.

References: src/…/DefaultExternalIdentityResolver.cs• L18-84 src/…/RejectUnlinkedIdentityPolicy.cs• L7-27 src/…/CreateUserUnlinkedIdentityPolicy.cs• L7-34 src/…/MatchExternalUserUnlinkedIdentityPolicy.cs• L7-45 src/…/ExternalIdentityUserProvisioningService.cs• L21-88 src/…/ExternalIdentityLinkManagementService.cs• L25-163 src/…/IdentityLinkEndpoints.cs• L12-164 src/…/DefaultPermissionGrantResolver.cs• L16-59 src/…/ExternalAuthenticationModels.cs• L135 src/…/ExternalAuthenticationRoleDeletionDependencyContributor.cs• L21-49 src/…/ExternalAuthenticationRoleDeletionDependencyContributor.cs• L71-259

OpenID Connect support

Authorization code flow

OpenID Connect (OIDC) is the identity layer built on OAuth 2.0. Elsa supports the OIDC authorization-code flow through a protocol adapter. The adapter creates a provider request, receives the callback, exchanges the code, validates the ID token, and returns a normalized external identity with bounded projected claims.

The flow uses S256 Proof Key for Code Exchange (PKCE), a state value for broker correlation, and a nonce for provider response correlation. Elsa validates the token issuer, audience, signature, lifetime, and nonce before it accepts the provider subject.

References: src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L17-18 src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L57-107 src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L188-211 src/…/OpenIdConnectConnectionSettings.cs• L40-44

Provider trust modes

An OIDC connection can use discovery or manual trust. Discovery reads the provider’s discovery document and obtains the issuer, authorization endpoint, token endpoint, and optional user, key, and logout endpoints. Manual trust requires an explicit issuer and explicit endpoint and signing-key trust data. Both modes require safe HTTPS provider endpoints.

The adapter descriptor exposes these choices to connection management surfaces. It also declares whether the connection supports provider testing, preview, and upstream logout. The adapter always requires the openid scope and does not permit a connection to disable upstream S256 PKCE.

References: src/…/OpenIdConnectSettingsParser.cs• L7-79 src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L23-44 src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L136-151

Provider callbacks and logout

Elsa owns the callback address used by the upstream provider. The deployment supplies the public callback base URI, and Elsa adds a connection-specific path for sign-in, preview, or logout. The authentication client must register the final callback and logout addresses before the broker accepts a request.

OIDC logout is optional because a provider may not expose an end-session endpoint. When enabled, Elsa keeps a protected upstream logout hint in the external session and uses it only for the configured logout mode. Local session revocation still occurs even when upstream logout is disabled or unavailable.

References: src/…/ExternalAuthenticationCallbackUris.cs• L5-31 src/…/ExternalAuthenticationBroker.cs• L420-520 src/…/OpenIdConnectExternalAuthenticationAdapter.cs• L116-125 src/…/ExternalAuthenticationOptions.cs• L191-218

Secret integration

Secret bindings

A secret binding is a typed reference to a value held outside the connection’s ordinary settings. OIDC uses a binding for the upstream client secret, and authentication clients can use a binding for their own confidential-client secret. The broker resolves bindings only when it needs them and passes sensitive values to the adapter without placing them in normal connection settings.

Adapter descriptors mark secret fields as secret bindings. The configuration source rejects a secret field supplied inside ordinary adapter settings, and returned settings redact declared secret fields. This keeps provider credentials separate from connection metadata and management responses.

References: src/…/ExternalAuthenticationModels.cs• L83-91 src/…/ExternalAuthenticationModels.cs• L108-132 src/…/ExternalAuthenticationContracts.cs• L90-111 src/…/ConfigurationSecretBindingResolver.cs• L7-31 src/…/AdapterSettingsSecretFieldGuard.cs• L6-51

Secret backends

The external authentication domain uses a resolver registry so a connection can refer to more than one secret backend. Configuration bindings read deployment-owned values. The Elsa Secrets integration adds managed bindings backed by the Elsa Secrets system and gives connection management a write-only way to stage a new value.

The resolver returns both a sensitive value and a generation fingerprint. Elsa stores the fingerprint rather than the value in flow state. If the secret changes during an authorization flow or while a session is refreshed, Elsa treats the connection material as changed and requires a new trusted flow.

References: src/…/ExternalAuthenticationContracts.cs• L90-108 src/…/ExternalAuthenticationBroker.cs• L554-579 src/…/DefaultExternalAuthenticationTokenIssuer.cs• L31-53 src/…/ElsaSecretsExternalAuthenticationFeature.cs• L10-22

EF Core persistence providers

Durable authentication state

The EF Core persistence option gives external authentication durable storage for connections, identity links, broker transactions, authorization grants, sessions, refresh tokens, connection observations, preview results, and registry versions. This state lets multiple Elsa nodes share login progress and lets administrators revoke sessions after the original sign-in.

The external authentication context is a separate data boundary. Its stores translate authentication models to database records while keeping provider-independent broker and identity contracts stable.

References: src/…/ExternalAuthenticationElsaDbContext.cs• L6-59 src/…/ExternalAuthenticationPersistenceMapper.cs• L6-32 src/…/ExternalAuthenticationPersistenceMapper.cs• L134-212 src/…/EFCoreExternalAuthenticationSessionStore.cs• L9-25

Provider choices

The shared EF Core feature defines the external authentication context and store registration. A database provider then supplies its connection setup and migration assembly. The available provider choices are SQLite, SQL Server, PostgreSQL, MySQL, and Oracle.

ProviderUse
SQLiteLocal or file-backed relational storage
SQL ServerSQL Server deployments
PostgreSQLPostgreSQL deployments
MySQLMySQL deployments
OracleOracle Database deployments

The provider-specific features keep the same external authentication data model while applying the database driver and provider schema rules. Oracle also applies large-object mappings for authentication JSON and protected payload data.

References: src/…/EFCoreExternalAuthenticationPersistenceFeature.cs• L9-20 src/…/EFCoreExternalAuthenticationPersistenceShellFeatureBase.cs• L6-16 src/…/SqliteExternalAuthenticationPersistenceShellFeature.cs• L14-35 src/…/SqlServerExternalAuthenticationPersistenceShellFeature.cs• L13-27 src/…/PostgreSqlExternalAuthenticationPersistenceShellFeature.cs• L14-35 src/…/MySqlExternalAuthenticationPersistenceShellFeature.cs• L14-35 src/…/OracleExternalAuthenticationPersistenceShellFeature.cs• L14-29

Session consistency

An external session records the connection material revision and secret generation fingerprint that were trusted at sign-in. Token issue and refresh compare those values with the current connection. A changed connection or secret therefore invalidates the old session instead of allowing it to continue with unknown provider settings.

Refresh tokens are rotated as part of a guarded store operation. A reused or racing refresh token causes the session to become revoked. The session administration endpoints expose tenant-bounded session listing and revocation when the optional operational surface is enabled.

The in-memory session store provides the same session contract for process-local use. It applies refresh rotation and revocation as one synchronized operation, returns copies of session data, and clears protected upstream logout data when a session is revoked or expires.

References: src/…/ExternalAuthenticationModels.cs• L235-258 src/…/DefaultExternalAuthenticationTokenIssuer.cs• L23-53 src/…/EFCoreExternalAuthenticationSessionStore.cs• L71-123 src/…/ExternalAuthenticationSessionEndpoints.cs• L16-103 src/…/InMemoryExternalAuthenticationSessionStore.cs• L8-115

Security boundaries

Request and provider controls

External authentication treats provider data and browser input as untrusted. The broker restricts requests to enabled registered clients, approved callback and return paths, and S256 PKCE. Provider egress rules restrict HTTPS, destinations, redirects, timeouts, response sizes, and optional host allowlists.

The domain also bounds broker transactions, one-time completion codes, previews, and sessions. Anonymous discovery, initiation, callback, and token exchange operations have separate rate limits. These controls reduce the impact of forged callbacks, unsafe provider metadata, large responses, and repeated login attempts.

References: src/…/ExternalAuthenticationBroker.cs• L531-598 src/…/ExternalAuthenticationOptions.cs• L111-189 src/…/ExternalAuthenticationOptions.cs• L191-202 src/…/ServiceCollectionExtensions.cs• L58-60

Session administration

Session administration is an optional, permission-guarded operational surface. It limits reads to the current tenant and returns safe session metadata. Revocation removes the session’s ability to issue tokens and records a security event for the administrator action.

Connection administration uses the same permission evaluator as endpoint permission gates when a request performs an extra protected action. This keeps wildcard permission grants consistent with the main authorization path instead of relying on direct claim comparisons.

References: src/…/ExternalAuthenticationSessionEndpoints.cs• L16-46 src/…/ExternalAuthenticationSessionEndpoints.cs• L67-103 src/…/ExternalAuthenticationOptions.cs• L233-244 src/…/ConnectionEndpointSupport.cs• L40-54

Change checklist

When these files or sections are changed, remember to consider these:

  • When the base service registration changes, keep the single-node defaults, replacement points for durable stores, authorization resources, rate limits, and health reporting aligned.
  • When an adapter setting or its version changes, keep the adapter descriptor, settings parser, migration path, and stored connection version aligned.
  • When a descriptor declares a new secret field, keep that field out of ordinary adapter settings and provide the required resolver and managed-secret path.
  • When connection material or secret generation changes, review callback state, session validation, refresh behavior, and any active-session revocation policy.
  • When connection management changes, keep revision ETags, If-Match preconditions, ownership rules, mutation error results, and permission evaluation aligned.
  • When identity scope or connection-key rules change, review external identity links, session queries, and tenant boundaries together.
  • When an unlinked identity policy or matcher changes, review its allowed deployment types, no-match behavior, user tenant checks, and default role selection together.
  • When a permission grant source or claim projection changes, review deployment allow and deny boundaries before changing the connection contract.
  • When a role becomes a default role in a just-in-time policy, keep role deletion dependency inspection, replacement authorization, connection revision checks, and tenant scope aligned.
  • When EF Core authentication data changes, update the mapper, context model, and migration set for each selected database provider.
  • When a provider is added or renamed, align its programmatic feature, shell feature, connection setting, migration assembly, and package manifest metadata.

Important failure modes

TriggerConsequenceGuard
A host keeps the default in-memory state stores while authentication runs on more than one nodeLogin progress, sessions, or registry state is not shared across nodesReplace the process-local stores with the matching durable persistence services before enabling a multi-node deployment.
A required provider secret is missing or its resolver is unavailableThe connection is not usable or the provider flow fails without sending the requestDeclare the field as a secret binding and check its resolver state during connection assessment.
The provider callback base URI or client callback registration is invalidThe connection is rejected or the broker refuses the authorization requestUse a trusted HTTPS callback base and register the exact client callback URI.
A connection mutation omits the current If-Match revision or uses a stale revisionThe management request is rejected or the caller must reload before changing current stateReturn the revision as an ETag and require the matching quoted revision for mutation.
A caller tries to mutate a configuration-owned connection or performs a protected extra action without its permissionThe operation is rejected without changing deployment-owned settings or protected policy stateEnforce ownership and route extra checks through the shared permission evaluator.
The connection changes after authorization startsThe callback or token exchange is rejected as a changed flowCompare the connection material revision and secret fingerprint before completion.
An external identity has no allowed Elsa user linkAuthentication succeeds upstream but Elsa does not issue a sessionKeep the reject policy as the default or configure an approved matcher or provisioning policy.
A matcher returns a user outside the target tenant or a configured default role no longer existsProvisioning stops without linking the external identityValidate the selected user and every default role through the identity contracts before creating the link.
Two first sign-ins provision the same external identity at the same timeA missing uniqueness rule can link the identity to competing usersEnforce uniqueness on the tenant, connection, issuer, and subject tuple and converge concurrent provisioning on the winning link.
An administrator tries to prelink, replace, or unlink across tenant scopeThe operation could disclose or change another tenant’s identity mappingRequire a resolved tenant and apply tenant checks in both the management service and link store.
A role used by a just-in-time policy is deleted without dependency remediationNew external users can receive an invalid default-role reference or provisioning can failInspect configuration and stored connections in the role scope, then remove the role or authorize a safe replacement before deletion.
A refresh token is reusedThe external session is revoked and cannot issue more tokensRotate refresh tokens in the session store and treat a failed rotation as reuse.
EF Core model and provider migrations are out of syncAuthentication state cannot be created, read, or migrated reliablyKeep the external context model and every selected provider migration set aligned.

Key files

FileWhy to read it
src/…/ServiceCollectionExtensions.csShows the protocol-neutral service foundation, single-node defaults, extension registration, and replacement points for host integrations.
src/…/ExternalAuthenticationBroker.csShows the end-to-end discovery, sign-in, callback, token, and logout boundaries.
src/…/ExternalAuthenticationModels.csDefines the connection, external identity, transaction, and session concepts used across the domain.
src/…/ExternalAuthenticationContracts.csDefines the extension points for adapters, connection sources, secret resolvers, identity resolution, grants, and persistence.
src/…/DefaultIdentityProviderConnectionRegistry.csShows how configuration and database connection sources become the effective login registry.
src/…/ConnectionEndpointSupport.csShows shared connection-management rules for optimistic concurrency, mutation errors, ownership, and extra permission checks.
src/…/DefaultExternalIdentityResolver.csShows how an external identity is found, rejected, linked to an existing user, or sent to provisioning.
src/…/ExternalIdentityUserProvisioningService.csShows the provider-independent rules for existing-user selection and credential-less user creation.
src/…/ExternalIdentityLinkManagementService.csShows tenant-safe prelink, replacement, unlink, and audit boundaries.
src/…/IdentityLinkEndpoints.csShows the permission-guarded administration surface for external identity links.
src/…/ExternalAuthenticationRoleDeletionDependencyContributor.csShows how role deletion accounts for default roles used by external authentication provisioning policies.
src/…/MatchExternalUserUnlinkedIdentityPolicy.csShows how a trusted matcher can link an unlinked identity or apply a safe no-match action.
src/…/OpenIdConnectExternalAuthenticationAdapter.csShows the protocol-level OIDC authorization, token validation, claim projection, and logout behavior.
src/…/OpenIdConnectSettingsParser.csShows the trust modes and safe OIDC connection settings accepted by Elsa.
src/…/ConfigurationSecretBindingResolver.csShows how deployment-owned secret references resolve without exposing secret values through connection data.
src/…/ElsaSecretsExternalAuthenticationFeature.csShows the integration boundary between external authentication and managed Elsa Secrets.
src/…/ExternalAuthenticationElsaDbContext.csDefines the durable external authentication data boundary.
src/…/ExternalAuthenticationPersistenceMapper.csShows the translation between authentication models and database records.
src/…/EFCoreExternalAuthenticationSessionStore.csShows durable session lookup, refresh-token rotation, and revocation behavior.
src/…/InMemoryExternalAuthenticationSessionStore.csShows the process-local session store contract and its guarded refresh and revocation behavior.
src/…/OracleExternalAuthenticationPersistenceFeatureExtensions.csIllustrates how a provider-specific package adds database setup and model rules to the shared persistence feature.