Dify SSO and identity integration

A practical plan for putting self-hosted Dify behind your identity provider, covering what the Community edition offers, how Enterprise SSO works with Entra ID or Okta, and how scopes and sessions affect access.

On this page

Why Dify SSO takes more planning than a login screen

SSO for Dify is an Enterprise edition capability, while the self-hosted Community edition signs users in with local accounts. That edition boundary is the first decision to settle, because the Community stack will not give you corporate sign-in without a change in license. For an IT or security lead, the hard part is not clicking through a provider wizard. It is choosing the protocol (OpenID Connect, SAML or OAuth2 under the Dify Enterprise SSO documentation), deciding whether SSO governs workspace access, web app access or both, and aligning session duration with the policy your identity team already enforces.

Sign-in settings also depend on secret handling. The SECRET_KEY variable signs session cookies and JWTs and encrypts OAuth credentials, and changing it after deployment logs out all users. That means the key must be generated, stored and rotated under your secrets process before the identity provider is connected, not after. Confirm with your Dify Enterprise account team which identity providers and settings are supported in the version you will deploy, and which environment variables the SSO setup reads, since these details differ between releases and between Community and Enterprise. Plan a test tenant or staging workspace to validate sign-in, role mapping and logout before any staff account depends on it.

Treat the identity design as a deliverable with an owner, a test script and a rollback path. Record who can create workspaces, which groups map to workspace roles, how web app audiences are restricted, and how a departing employee's access ends across both scopes. Ask any implementation partner or vendor to show these controls working in your environment, not only in a demo, because sign-in behavior is where access problems usually surface.

Which parts of Dify carry identity

Identity in a self-hosted Dify runs through a small set of components: the api and web services, the SECRET_KEY, the Nginx entry point and the identity provider registration. Each one has a specific job, and a misconfiguration in any of them can log users out, expose a web app or break the sign-in redirect.

The api and web services

The api service handles authentication requests and issues the session state that the web service relies on when a user opens the console or a published app. Both services must agree on the public address Dify is served from, because redirect URIs registered with the identity provider are built from that address. Check the console URL and the app URL settings before you register anything, and confirm them against your current environment file and the version you deploy.

Environment variables

SECRET_KEY and what it protects

The SECRET_KEY signs session cookies and JWTs and encrypts stored OAuth credentials. Changing it after deployment logs out every user and can make stored identity provider secrets unreadable, so generate it once, store it in your secrets manager and back it up with the database. Treat it as a credential in your rotation plan, not as a setting you adjust during troubleshooting.

Workspace access scope

Workspace SSO controls who can sign in to the Dify console and which workspace they land in. This is where roles such as editors and administrators are granted, so it governs who can build workflows, change model credentials and read app logs. Decide early which identity provider groups map to which workspace roles, and document that mapping as part of your access review.

Web app access scope

Web app SSO controls who can open a published application, separately from console access. A customer or employee may need an app without any console rights, so the two scopes should be configured and tested independently. Confirm which apps are public, which require sign-in and whether any app is reachable without identity at all.

Nginx entry point

Nginx is the public entry point in the Docker Compose stack, so it terminates the browser connection and forwards requests to the web and api services. Callback URLs, forwarded headers and TLS settings all pass through it. A wrong host or protocol header here is a common cause of redirect loops and failed sign-ins, so test the full login flow through the same hostname your users will use.

Docker Compose guide

Identity provider registration

The identity provider holds the application registration that Dify uses: client ID, client secret, redirect URI and the claims Dify expects, such as email and name. Enterprise SSO supports OpenID Connect, SAML and OAuth2 with providers such as Microsoft Entra ID and Okta. Confirm the redirect URI exactly matches your deployed address and record who owns the registration and the secret rotation schedule.

Enterprise SSO docs

Choosing the protocol, scope and session model

This table compares the Enterprise SSO protocols, the two SSO scopes and session duration policy for Dify, with the administration, user experience and support effort each choice creates. Read each row against your identity provider's capabilities and your user population, then confirm the exact options in the Enterprise version you are quoted.

DecisionWhat it means for DifyOperational trade-offWhen it fits
OpenID ConnectEnterprise SSO option listed in the Dify Enterprise SSO documentation, commonly paired with Microsoft Entra ID or OktaClient registration, redirect URI and claim mapping must be set in both the identity provider and Dify; claim changes can break sign-inModern identity providers where you want group or attribute claims mapped to Dify access
SAMLEnterprise SSO option listed in the Dify Enterprise SSO documentation, with Entra ID and Okta as named providersCertificate rotation and metadata exchange need an owner; expiry of signing certificates is a common outage causeOrganizations whose security standard or existing application catalog is SAML-based
OAuth2Enterprise SSO option listed in the Dify Enterprise SSO documentation, including GitHub as a listed identity sourceScopes and user profile fields vary by provider, so confirm which identity attributes Dify actually receivesTeams that already authenticate developers through GitHub or a provider with an OAuth2 flow
Workspace SSOControls sign-in to the Dify console and the workspaces users manage or build inUsers who build apps need workspace access, so role mapping and offboarding must be reviewed as carefully as sign-inInternal builders, prompt engineers and administrators who create and edit AI apps
Web app SSOControls who can open a published web app, separately from workspace accessRequires a separate access policy for each published app; app owners must maintain it as apps are addedEmployee-facing or customer-facing apps where end users should not hold console accounts
Session duration policySession lifetime is governed by Dify configuration, and changing SECRET_KEY after deployment logs out all usersShort sessions raise re-authentication friction and support tickets; long sessions extend exposure of a stolen sessionSet the policy with your security team and identity provider settings, and confirm the exact configuration keys for your version

How to configure SSO for Dify in order

This sequence takes a self-hosted Dify from local accounts to identity-provider sign-in, with group-based workspace access, a scoped web app policy, a pilot group and a final lockdown of local sign-in.

  1. Confirm edition and SSO entitlement

    Before any configuration, confirm with Dify whether your deployment is entitled to SSO. The Community edition is free and limited to a single workspace, while the Enterprise edition is custom priced and adds SSO, multiple workspaces and professional support, according to Dify's pricing page. Ask the vendor in writing which Enterprise version and deployment method your license covers, and confirm which identity protocols (OpenID Connect, SAML or OAuth2) and providers are included. Done means you hold a written entitlement and a named protocol choice for the identity provider you will use, such as Microsoft Entra ID or Okta.

  2. Register Dify as an application in the identity provider

    In your identity provider, create an application for Dify using the protocol you confirmed. Take the exact redirect URIs and callback paths from the Dify Enterprise SSO documentation for that protocol and copy them without modification, since a mismatch is a common cause of failed sign-ins. Record the client ID, client secret or SAML metadata, and the issuer or metadata URL in your secrets store, not in tickets or chat. Done means the application exists in the identity provider with the documented redirect URIs and you have the credentials ready for the Dify settings.

  3. Map groups or roles to Dify workspace access

    Decide which identity provider groups should map to which Dify workspace roles before you enable sign-in. Create or select groups in the identity provider for administrators, builders and read-only users, and confirm that the identity provider emits the group or role claim that Dify expects for your protocol. Keep the mapping in a short table owned by the identity team and the Dify administrator. Done means you have a written group-to-role table and a test user in each group whose token or assertion shows the expected group value.

  4. Configure Dify SSO settings for the chosen protocol

    In the Dify Enterprise administration settings, enter the identity provider values for your chosen protocol: client ID and secret for OpenID Connect or OAuth2, or metadata and entity settings for SAML. Apply the group or role mapping from the previous step and keep SSO on a non-production or pilot instance first if your environment allows it. Store the SECRET_KEY and other sensitive values as documented, because changing SECRET_KEY after deployment logs out all users. Done means the settings save without error and an attempted sign-in redirects to the identity provider and returns to Dify.

  5. Set the web app access scope

    Dify separates SSO scope for workspace access from SSO scope for web app access, so decide them independently. Workspace access governs who can build and administer apps, while web app access governs who can use published apps. For each published app, choose whether it requires SSO sign-in, is open to anyone with the link, or is limited to specific groups where the product supports it. Confirm this setting against the current Dify Enterprise documentation for your version. Done means a published app requires the intended sign-in and an unauthenticated browser session is refused or redirected as designed.

  6. Test with a pilot group of non-admin accounts

    Run a pilot with a small set of real users who hold ordinary roles, not only administrators. Each pilot user should sign in through the identity provider, confirm they land in the correct workspace with the expected role, and confirm they can use only the apps their scope allows. Include one user who should be denied, such as someone outside the mapped groups, and check that access is refused. Record the results and any claim or group mismatches. Done means every pilot user has a documented pass or a logged fix, and the denied-user test fails as expected.

  7. Lock down local sign-in and verify the result

    Once the pilot passes, restrict local email and password sign-in according to your policy and keep one break-glass administrator account with a stored credential and a named owner. Confirm the identity provider can disable or remove a user and that Dify reflects that change at the next sign-in, and document how session duration follows your identity provider and Dify settings. Re-run the non-admin and denied-user tests after the change. Done means local sign-in is limited as intended, the break-glass account is tested, and the evidence of each check is filed with your change record.

What the Community edition can and cannot do for sign-in

The free self-hosted Community edition does not include SSO. According to the Dify pricing page, it is limited to a single workspace, and SSO, multiple workspaces and advanced security are listed as features of the custom-priced self-hosted Enterprise edition. If your identity provider must govern who reaches Dify, plan for Enterprise from the start, or accept that Community sign-in will be managed by Dify itself. Before you commit to a design, read the pricing page for the current edition boundaries, since the feature split is the decisive input for this topic.

Until an Enterprise decision is made, the practical controls are local accounts with a strong password policy, and network-level restriction in front of the Nginx service that Docker Compose deploys. Put the console behind your VPN, private network or a reverse proxy that enforces your own access rules, and confirm that the Nginx entry point is the only exposed path to the api and web services. Treat local accounts as a temporary identity store: they will need to be deprovisioned by hand when people leave, so keep an owner list and review it on a fixed schedule.

Before you rely on any Community sign-in behavior, confirm it against the exact version you deploy. Check the current self-hosting documentation and the release notes for the version you plan to run, and test password rules, account lifecycle and session handling in a staging instance. Record the upgrade path to Enterprise as an explicit decision, with a named owner, so that moving to federated sign-in later does not require reworking your access model under pressure.

How SSO differs by deployment model

The Community edition is deployed with Docker Compose and runs the api, worker, web, plugin daemon and supporting services such as PostgreSQL, Redis, Weaviate, Nginx, a code sandbox and an SSRF proxy. The self-hosted Community edition is free and limited to a single workspace, and the Enterprise SSO integration described in the Dify Enterprise documentation is not part of it. Teams that need a single sign-on provider for Dify users should not plan on configuring it in this model without first confirming the current options for the release they intend to run.

  • No Enterprise SSO: SSO over OpenID Connect, SAML or OAuth2 is documented for Dify Enterprise, not for the Community stack.
  • Local accounts: Users sign in with accounts managed inside Dify, so access reviews and offboarding happen in the console.
  • Single workspace: The edition's workspace limit means workspace-level and web app access decisions are made within one tenant.
  • Minimum host sizing: The Compose deployment starts at 2 CPU cores, 4 GB of RAM and Docker Compose 2.24.0 or later.
  • Upgrade effect: Any authentication workaround added to Compose files or Nginx must be re-tested on every release.

Before committing to this model, confirm with the Dify documentation for your target version whether any identity option exists in the Community edition and how account lifecycle is handled.

How a user signs into Dify through the identity provider

The sign-in starts in the user's browser, which reaches the Dify web and api services through Nginx. Dify hands the browser to the identity provider over the Enterprise SSO protocol, and the provider returns the user to a callback on Dify. Dify then issues its own session cookie, and SECRET_KEY, which signs session cookies and JWTs, governs that session. Web app access follows a separate path, so confirm which SSO scope each user group falls under before go-live.

Sign-in flow for Dify workspace access through an external identity provider.

Protecting sessions, secrets and admin access

Identity integration is only as strong as the secrets and sessions behind it. The cards below cover the settings that sign users in and keep them signed in, the fallback path when the identity provider is unavailable, and how group membership translates into Dify permissions. Review them together before any user is routed through single sign-on.

Set SECRET_KEY before go-live

The SECRET_KEY variable signs session cookies and JWTs and encrypts OAuth credentials. Changing it after deployment logs out every user, and it also affects stored credentials, so treat it as a one-time decision. Generate a long random value before the first start, store it in your secrets manager, and confirm that every environment file and restore path uses the same value. Record where it lives so a rebuild does not invent a new one.

Environment variables

Encryption of OAuth credentials

OAuth client secrets for identity providers are encrypted with the same key material as session signing, so their protection depends on how SECRET_KEY is handled. Confirm who can read the .env file and container configuration, and restrict access to the Dify host and its backups. Ask your identity team to rotate the client secret on a schedule and to record which Dify environment holds each registered application.

Session duration policy

Session lifetime should be set as a documented policy, not left at whatever the defaults happen to be in your version. Agree the maximum session length and the idle timeout with your security team, and check how each setting applies to the console and to published web apps, since those are separate access paths. Test sign-out, expiry and re-authentication with a real account before the rollout is announced.

Least-privilege group mapping

Map identity provider groups to Dify workspace roles deliberately. Give administrator rights only to a small named group, keep workspace access and web app access in separate groups, and remove any default role that grants more than a user needs. Review the mapping after every organizational change, because stale group membership is the most common source of excess access in SSO setups.

Break-glass admin access

Plan a local administrator path that works when the identity provider is down, misconfigured or unreachable. Keep its credentials in a sealed store, limit who can retrieve them, and test that the path still works in a non-production copy. Alert on every use, and confirm with the vendor or your own environment whether the chosen edition keeps a local login available once SSO is enforced.

TLS on the Nginx entry point

All sign-in traffic should reach Dify over HTTPS. Terminate TLS at the Nginx entry point or at a load balancer in front of it, use certificates from your own trust chain, and confirm that the redirect URIs registered with the identity provider use the same external hostname. Mismatched schemes or hostnames are a frequent cause of failed sign-in and are easy to miss during testing.

How to test SSO and confirm it fails safely

The point of SSO testing is to prove that only the right people get in through the identity provider, that scope limits hold, and that a failed login path does not leave Dify open. Run these checks in a staging instance with test accounts before any production user is switched over. Build a matrix with one row per identity provider group and one column per outcome: successful sign-in for each group that should have access, denial for a user in the directory who sits outside every permitted group, and denial for an account that is disabled or removed. Repeat the matrix separately for workspace access and web app access, because the two SSO scopes are configured independently and a user who passes one scope may still fail the other. Confirm the exact group claim or attribute mapping your identity provider sends, since a mismatch there is the most common cause of both false denials and false grants. Confirm current settings and claim behavior with your Dify Enterprise contact and the Dify Enterprise SSO introduction before you write the test plan.

Next, test session behavior. Sign in, leave the session idle, and confirm that Dify requires re-authentication when the configured session lifetime expires. Then sign out in Dify and check whether the identity provider session also ends, and whether a second browser session stays valid. Note that the SECRET_KEY value signs session cookies and JWTs, so rotating it during testing will log every user out and invalidate your results. Test the admin fallback path deliberately: block the identity provider endpoint in staging and confirm what a local administrator can still do, and whether an ordinary user can reach the console through a retained password or a cached session. The expected result is that local access stays restricted to named administrators, that the fallback account is not used for daily work, and that the failure is logged and visible to operations staff.

Treat any failed test as a stop condition for go-live. A failure should leave local admin access controlled and limited to named break-glass accounts, not open to anyone who can reach the login page. Record the expected and actual result for each case, the Dify version under test, and the environment settings used, so the same matrix can be rerun after each upgrade. Ask your implementation partner or internal team to document who holds the break-glass credentials, where they are stored, and how access to them is logged. Re-run the full matrix after every identity provider change, every Dify upgrade and every change to SECRET_KEY or session settings, because each of these can alter sign-in behavior without any visible change in the console.

What drives SSO effort and how to keep it down

This table lists the factors that change how much work an Dify SSO integration takes, how each one moves effort, and what to do to keep it contained. Read it before scoping, since most of the effort comes from the number of identity sources, the group model and the number of separate access scopes rather than from the sign-in flow itself.

DriverWhy it changes effortHow to keep it down
Identity providers and protocolsEach provider and protocol (OpenID Connect, SAML or OAuth2) needs its own client registration, claim mapping and test cycle, and Enterprise SSO is needed for these optionsStandardize on one protocol and one identity provider for the Dify console, and confirm which protocols your Dify edition supports before design starts
Group and role modelMapping directory groups to Dify workspace roles is where most access errors appear, especially when groups are nested or named inconsistentlyDefine a small set of roles up front, map only directory groups that already exist, and document who approves membership changes
Workspaces and web appsWorkspace access and web app access use separate SSO scopes, so each scope needs its own rules and its own testingLimit the number of workspaces and make web app access follow one shared policy rather than per-app exceptions
Environments (dev, test, production)Each environment needs its own redirect URIs, client secrets and test users, and drift between them causes sign-in failures after promotionKeep environment configuration in the same documented template, and rotate secrets through your normal secret store
Compliance evidence requirementsAssessors usually ask for the access model, the approval trail for role assignments, session settings and proof of deprovisioning, which takes time to assembleAgree the evidence list before build, export configuration and access reviews on a fixed schedule, and keep them with the change record
Existing Entra ID or Okta tenantsTenant policies such as conditional access, MFA, group naming rules and app assignment controls can block or change sign-in, and the owners may sit in another teamInvolve the tenant administrators early, reuse existing enterprise application patterns, and confirm the tenant owner for each change
Pilot cohortsRolling out to every user at once multiplies support questions and makes it harder to isolate a mapping or policy errorStart with a small named pilot group, fix mapping issues there, then widen access in stages
Session duration and sign-out rulesSession length and logout behavior need agreement from security and the business, and changes can require retesting across scopesSet session rules once from a written policy, and test sign-out for both the console and the web apps before widening access

What to monitor, back up and document after SSO goes live

How do I monitor Dify sign-in failures and identity provider outages?

Watch sign-in failures at two layers: the identity provider's own sign-in logs and Dify's API and worker logs for callback and token errors. Identity provider problems usually show up as a spike in failed callbacks, expired tokens or users redirected to an error page, while Dify-side problems often appear as repeated login attempts that never complete. Set alerts on the identity provider's failure rate and on Dify container restarts, and confirm with your identity team which health checks they can run against the OIDC discovery endpoint or SAML metadata. Agree in advance who owns the response when Entra ID or Okta is degraded, and whether local administrator access exists as a documented fallback for recovery.

What should I back up for Dify SSO settings and SECRET_KEY?

Back up the .env file, the database and the settings that define your identity integration, and store them in your approved backup system. The most sensitive item is SECRET_KEY: the Dify environment reference says it signs session cookies and JWTs and encrypts OAuth credentials, and changing it after deployment logs out all users. Record its value in your secrets store with an owner and a restore procedure, and confirm that a restored environment reuses the same key, because a different key can break stored OAuth credentials. Keep the identity provider's client ID, redirect URIs and tenant or realm details in the same documented record, so a rebuild does not depend on someone's memory.

Why should I back up Dify before every upgrade?

The Dify Docker Compose docs recommend a backup before every upgrade, and the reason is that a failed upgrade is much easier to reverse from a known good state. Take the backup before you pull a new version, and confirm it can be restored in a non-production copy at least once. Dify minor releases arrive roughly monthly according to the Dify releases page, so this step recurs throughout the life of the platform, not just at go-live.

What identity settings should I review during each Dify upgrade?

Review the identity settings every time you upgrade, using the upgrade guide for the target version on the GitHub Releases page and the current .env.example. Check for new or renamed variables related to login, session duration, SSO and callback URLs, and compare them with your deployed .env. Also confirm the identity provider application still points at the correct redirect URI after any change to the public hostname or proxy path. Treat an upgrade as a test event: sign in with a test account for each access scope before you release it to users.

How often should I rotate the OAuth client secret for Dify?

Rotate the OAuth client secret on a schedule set by your identity and security policy, and also after any suspected exposure or staff change with access to the configuration. The sequence matters: create a new secret in the identity provider while the old one still works, update Dify's configuration, verify sign-in for each access scope, then revoke the old secret. Confirm with your identity provider administrator how overlapping secrets are supported, and record the expiry date in your operations calendar, since many providers expire client secrets automatically.

What should I document about Dify access scopes for auditors?

Document which users can reach the workspace and which can reach each web app, and how each group gets that access. Dify Enterprise SSO documentation describes separate SSO scopes for workspace access and web app access, so your record should show the identity provider groups or applications mapped to each scope, who approves changes, and how removals are handled. Include the session duration setting, the SECRET_KEY custody procedure, backup and restore records, and the upgrade log entries that show identity settings were reviewed. Independent auditors decide whether these controls meet a given framework; DeployOpen prepares the systems and evidence for that review but does not issue audit reports or certifications.

How DeployOpen scopes and hands over Dify SSO work

DeployOpen scopes Dify SSO as a line item in a fixed-scope engagement, agreed in writing before any configuration starts. The written scope names the identity provider, the protocol (OpenID Connect, SAML or OAuth2), whether sign-in covers workspace access, web app access or both, and which Dify edition the work targets. Because Community and Enterprise differ on SSO, the first decision is confirming the edition, since the Community edition does not provide the enterprise SSO path that this section assumes. The scope also states what the client provides: an administrator account in the identity provider, a group or role model to map, and a test user population for verification. Quotes follow from that written scope, so the client should ask for each of these items to be listed separately rather than bundled into a general integration line.

Configuration happens inside the client's own infrastructure, so the identity provider settings, redirect URIs, SECRET_KEY handling and session settings stay under the client's control. DeployOpen documents the access model as part of the work: which groups reach which workspace, who can publish web apps, who can administer the identity connection, and how a departing user loses access. Test evidence covers sign-in for each protocol and scope, denial for users outside the permitted groups, session expiry behavior, and a check that changing SECRET_KEY was not needed in the rollout. Handover includes runbooks for adding a new identity provider, rotating the client secret, and troubleshooting failed sign-ins. Ongoing support, including upgrade checks against SSO settings after new Dify releases, is available as a retainer.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.