AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
icon: 🛡️
EE Authentication (SSO/RBAC)
Enterprise auth layer extending CE with SAML 2.0 SSO, Google/GitHub federated OAuth, OTP email flows, per-project RBAC, and managed-auth JWT exchange for embedding. All SSO paths delegate to authenticationService.federatedAuthn() which creates/links a user and issues a standard AP JWT.
Entities & services
saml-authn/,federated-authn/,otp/,enterprise-local-authn/,project-role/(RBAC),ee-authorization.ts(preHandler hooks),managed-authn/.platform.federatedAuthProvidersstores{ saml: {entityId, ssoUrl, certificate}, google: {clientId, clientSecret} }.
How it works
- SAML SSO:
POST /v1/authn/saml/loginreturns IdP redirect; IdP POSTs assertion to ACSPOST /v1/authn/saml/acs; service parses email/name → federatedAuthn → JWT. Gated byplatform.plan.ssoEnabled. - Federated OAuth (Google/GitHub):
/v1/authn/federated/loginreturns redirect URL;/v1/authn/federated/claimexchanges code → JWT. Redirects always useFRONTEND_URL(no custom domain). - OTP (
EMAIL_VERIFICATION,PASSWORD_RESET,EMAIL_LOGIN): per-type expiry (OTP_EXPIRATION_MSinotp-service.ts: 24h verification, 10-min reset, 10-min login); states PENDING/CONFIRMED; one row per(identityId, type), DB-enforced. Resend re-delivers the existing pending value WITHOUT touching the row — expiry stays anchored to the value's creation, so resends cannot extend a (possibly compromised) OTP's lifetime; a new value is generated only once the old one is expired or spent (GIT-1733: the old early-return made resend a silent 204 no-op). The first two types carry arandomUUID()delivered as a link;EMAIL_LOGINcarries a 6-digit code the member types, and its row countsattemptsso it dies after five wrong guesses — counted in raw SQL for the same reason resend leaves the row alone, since touchingupdatedwould buy the guesser another window. Known bounded edge: a resend requested just before expiry delivers a short-lived link; the next resend regenerates. See 000027. - Enterprise local auth:
verifyEmail(confirms OTP → sets verified),resetPassword(confirms OTP → updates hash), both audit-logged. - RBAC:
assertPrincipalAccessToProject({principal, permission, projectId})andassertUserHasPermissionToFlow(maps FlowOperationType → Permission). Authorization hooks:platformMustHaveFeatureEnabled(402 FEATURE_DISABLED),projectMustBeTeamType,platformMustBeOwnedByCurrentUser.
Gotchas
- Until the passwordless work, CE could not send an OTP at all, despite the entity being registered for every edition.
otpModulewas registered only in the CLOUD and ENTERPRISE arms ofapp.ts, andemailService.sendOtpreturned early when the edition was neither. So on CE the table existed, the migration ran, and nothing could ever be sent.EMAIL_LOGINchanged that:otpModuleis now registered for COMMUNITY too, andEMAIL_LOGINis the one type carved out of the paid-edition send gate, so the primitive reaches every edition. The sign-in flow on top of it does not — 000032 put its three routes in a Cloud-only module that also needs a configured captcha, so the carve-out is currently unreachable and CE can still send nothing. The two link types are still paid-edition only. RBAC base types are CE; SSO, managed auth, federated OAuth are EE/Cloud only. - The public
POST /v1/otproute deliberately cannot mint a login code. ItsCreateOtpRequestBodynarrowstypetoEMAIL_VERIFICATION | PASSWORD_RESET, because that route is unauthenticated, carries norateLimitconfig, and applies none of the sign-up guards.EMAIL_LOGINis issued only throughPOST /v1/authentication/otp/request, which is rate limited and gated. Widening that enum back to the wholeOtpTypehands anyone an unthrottled "email a working sign-in code to this address" primitive. - A code sign-in must re-assert the platform's auth policy at verify time, not only at request time. On Cloud
platformUtils.getPlatformIdForRequestreturns null for every unauthenticated request, so the request-scoped branch never runs there and the platform is only known after the identity is resolved.verifyCodetherefore calls the sameassertEmailAuthIsEnabled+assertDomainIsAllowedpair on the resolved preferred platform; without that, an email code signs a member into a platform that has deliberately disabled email auth or removed their domain. It is not asserted at request time on purpose, because reporting those errors for a resolved address would turn the request endpoint into an existence oracle. otpService.confirmused to refresh its own resend lock.updatedis anupdateDatecolumn, so marking a row CONFIRMED touched it and the ten-minute guard then refused to issue that identity another code for ten minutes after a successful verify. Rows are deleted on confirm now.- One constant is both the expiry and the resend suppression.
TEN_MINUTESgatesconfirm's freshness check andcreateAndSend's "an OTP already exists" early return, so before this work a resend was impossible until the current credential expired, and the request endpoint still answered 204. Resend now re-delivers the existing value without touchingupdated. email-service.tsis not exhaustive overOtpType.frontendPathis a literal keyed by only two members but indexed by the whole union, so adding a member is a compile break; its siblingotpToTemplateis typedRecord<string, EmailTemplateData>, which type-checks and handsundefinedto the sender at runtime instead.- The SAML round-trip used to forget where the login was going, and the obvious fix moves a trust boundary. Three losses, all in the redirect and none in the assertion handling: the web app called
/api/v1/authn/saml/loginwith nofrom(saml-login-form.tsx,third-party-logins.tsx),/authenticatehardcodednavigate('/flows'), and/acsredirected tonetworkUtils.getRequestBaseUrl(req)— an origin with no path — so a subpath instance 404'd atexample.com/authenticate. Password sign-in hid all three by never leaving the origin; they surfaced the moment a login started elsewhere, so MCP OAuth (/mcp-authorize→/sign-in?from=…) abandoned the authorize request. The trap worth remembering: it is tempting to carry the starting origin through the IdP in RelayState. Do not./acsderives its redirect from the IdP's POST, whosex-forwarded-hostonly the operator's edge sets; capturing the origin at/logininstead hands that decision to an endpoint an attacker can call directly, andnetworkUtils.candidateHostsdeliberately prefersx-forwarded-host— so a spoofed header would mint a return target forevil.com, and a phished IdP link carrying it would deliver the victim's session token to/authenticate?response=. Signing or storing the captured origin does not close that; only resolving it against an allowlist would. What shipped avoids the question entirely: MCP consent is served from the frontend base (see [[mcp-server]]), so login leaves and returns to the same origin in the same tab.fromridessessionStorage(lib/federated-login-redirect.ts, saved byuseStartSamlLoginat the three SAML entry points, consumed and cleared at/authenticate). It stores only/mcp-authorize, exactly or followed by?— every other destination, including legitimate in-app deep links, is refused and SSO lands on the default page as it always has. That narrowness is deliberate: the mechanism exists for the one flow that cannot survive losing its continuation, and scoping it by destination keeps deployments without MCP on their existing code path. Gating it onAP_MCP_URLinstead would not work —getMcpUrlfalls back toAP_FRONTEND_URL, so theMCP_URLflag is never null, and/authenticateconsumes synchronously on mount while flags arrive async, and/acsbuilds its redirect from the request origin (new URL('/authenticate', networkUtils.getRequestBaseUrl(req))), which is the one place the SPA can route it. No RelayState, no Redis, no allowlist, and the origin never crosses the IdP. - Restoring the subpath on the SSO return breaks SAML sign-in on a prefixed instance, because the SPA cannot route a prefixed path — and the bare-origin version it replaced accidentally could. Verified end to end against a real SimpleSAMLphp IdP behind Kong (
strip_path: true) withAP_FRONTEND_URL=http://host/activepieces: the assertion validates and/acsredirects tohttp://host/activepieces/authenticate?response=…exactly as intended — and the SPA then bounces away with the session response unconsumed, becausecreateBrowserRouterhas nobasename(see [[web-feature-anatomy]]). Measured both ways on one harness:new URL('/authenticate', getRequestBaseUrl(req))drops the path, lands at the origin root, and signs in; restoring the prefix kills the login. So the two kinds of URL AP emits have opposite requirements and must not share a helper: protocol URLs the server advertises (OAuth issuer and endpoints, ACSDestination, webhooks, invitation links) need the configured base, while browser landing routes (/authenticate,/mcp-authorize,/sign-in) must stay wherever the SPA can actually route, which today is the origin root. With the origin-root return and the UI at the root, the whole SSO-into-MCP chain completes in a browser — IdP credential form →/acs→/authenticate→fromrestored fromsessionStorage→ consent → code → token →tools/list; that chain is the point of thefromround trip, and it is what a prefixed instance loses. Until the SPA gainsbasename+ vitebase, prefixing a browser landing route is always wrong. - AP accepts only plaintext SAML assertions, and an encrypting IdP fails with a misleading error.
createSpsetsisAssertionEncrypted: true, but samlify reads that flag off the remote entity (flow.js:decryptRequired = from.entitySetting.isAssertionEncrypted), wherecreateIdpsetsfalse— so the SP-side flag is inert. It could not work anyway: samlify decrypts withentitySetting.encPrivateKey, which AP never sets (privateKeyholdssamlProvider.idpCertificate, used for signing). Point an IdP withassertion.encryptionon at it and the failure surfaces asERR_UNMATCH_ISSUER— not a decryption error — because the issuer comparison reads the assertion's issuer out of a decrypted document that does not exist. Configure IdPs to sign but not encrypt. - The SSO settings page (titled Authentication since ENG-977, route still
/platform/sso) is wrapped inPlanFeatureSample feature="sso", which renders the real page faded under an upgrade card whenssoEnabledis off. It has no sample data, so a locked platform sees its own real values. - The allowed-domain list only runs once a platform is known, so on Cloud it misses most first sign-ins. Self-hosted always knows the platform (the oldest one), so
assertDomainIsAllowedruns insignUpfor every provider and on every email-and-password and email-code sign-in; returning Google/SAML users skip it. On CloudgetPlatformIdForRequestisnullfor anyone not signed in, sosignUpruns without a platform and skips the check, andprovisionUserInvitationthen makes the person a member of every invited platform without checking either. Net effect on Cloud: password and email-code sign-ins are checked once the person is a member, Google is never checked, SAML only when the person has no account anywhere, and an invited person outside the list joins and is then refused at their next password sign-in. Community never checks. Until ENG-999 fixes this, the Authentication page copy is split by edition: Enterprise says the list limits who can join, Cloud says only "email and password sign-in"; ENG-999 removes the split. - To reproduce "SAML connected + pending domain" locally, go through the API, since the UI cannot create it. Verify a domain, save SAML (
POST /v1/platforms/:idwithfederatedAuthProviders.saml; placeholder metadata is accepted), thenPOST /v1/authn/saml/sso-domainwith a different domain: the new one is pending and SAML is kept. Switching discards the old domain's verification, so re-verifying it later needs a new TXT record. - "Verify DNS" asks the API host's own resolver, so a correct TXT record can still fail for a few minutes.
txtRecordMatchescalls Node'sresolveTxt, which uses the OS resolver (locally often Tailscale's100.100.100.100), not a public one; until that cache expires the old record set comes back. Comparedig TXT _activepieces-verify.<domain> @8.8.8.8with plaindigbefore suspecting code. Leftoveractivepieces-verify=records from earlier attempts are harmless: any matching record passes. - The Authentication page blocks removing the last working sign-in method in the UI only; the API still accepts it (ENG-483).
useSignInMethodsis the one place that decides what works: email on, Google really working (the provider flag, not the switch), SAML connected and, on Cloud, a verified domain (without one the sign-in page cannot reach SAML). Remove domain and Disable SSO are blocked when SAML is the only one left; turning email off is blocked when SAML is not connected and Google does not really work; turning Google off is blocked only when Google really works and email and SAML are both off, so a self-hosted Google switch without an OAuth client can always be turned off. platform.googleAuthEnabledis a saved switch that defaults totrue, not proof Google sign-in works. On self-hosted Google only works onceAP_GOOGLE_CLIENT_IDandAP_GOOGLE_CLIENT_SECRETare set. Whether it really works isTHIRD_PARTY_AUTH_PROVIDERS_TO_SHOW_MAP.google(credentials set and switch on), the flag the sign-in page uses for its Google button; any "is another sign-in method left?" check must read that flag, not the platform column. Because the flag folds in the switch, the frontend can only tell "not set up" while the switch is on; with it off the state is unknown. The Authentication page shows "Not set up" plus a Setup guide link only on self-hosted with the switch on, and the turn-on dialog states the requirement instead (link built withadminDocs.urlfrom the admin kit).- The SAML walkthrough keeps both steps mounted and hides the inactive one with a
hiddenclass, so a test that finds step 2 text passes even when navigation is broken. Assert on the step bar instead (aria-current="step",disabled) and onNext/Savestate. The SAML step opens only once the domain is verified, except when SAML is already connected (pre-domain setups), so those admins can still reach their connection and Disable. - Only removing a verified SSO domain deletes SAML; a pending one goes and SAML stays.
updateSsoDomain(null)deletes SAML only when the current verification isVERIFIED, so "Cancel verification" matchesexpirePendingSsoDomains, which clearsssoDomainandssoDomainVerificationafterPENDING_DOMAIN_TTL_HOURS(3) without touchingfederatedAuthProviders. A platform reaches "SAML + pending domain" when it set up SAML before #13071 added domains (May 2026, no backfill) and only now verifies one, or by changing the domain (the pre-ENG-977 page's "Update domain", or the API; ENG-994); deleting SAML there would remove SSO that was working. - Removing the SSO domain also deletes SAML, in one update.
updateSsoDomainwithnullclearsssoDomain,ssoDomainVerificationandfederatedAuthProviders.samlin the sameplatformService.update; the page's Remove domain is that one request. Without a domain the sign-in page could not start SSO anyway (/discoverneeds a verified domain), and new SAML connections already require one. History: #13071 shipped a Remove button that never worked (see the next bullet); #13072 dropped the button without a stated reason; ENG-977 fixed the server and brought it back. Changing to a different domain still keeps SAML while the new one is pending. The sign-in page's SSO path is closed then (no verified domain for/discover), but IdP-initiated sign-in or a direct/login?platformId=link still works, andassertEmailMatchesSsoDomainskips unverified domains on purpose so platforms that had SAML before domain verification keep working; so the platform's own IdP can sign in any email until the new domain verifies (ENG-994).verifySsoDomainon an already-verified domain returns without re-checking DNS, so the page only offers "Verify DNS" while pending. Removal deletes SAML rather than keeping it saved because SAML has no on/off state: a kept config would stay live with no domain check. When ENG-982 adds on/off, removal should switch to turning SAML off (and the remove dialog and docs that say "deletes" change with it). - Every domain claim gets a fresh TXT value, so a record left at the DNS provider never re-verifies anything.
computeNextVerificationissuesactivepieces-verify=<new apId>for any new or re-added domain, andtxtRecordMatchesneeds that exact value at_activepieces-verify.<domain>(any of the TXT strings there may match, so admins can add the new value beside the old one). Removing and re-adding a domain therefore always lands on PENDING, and a stale record cannot verify the domain for this platform or another one. platformService.updatewrites most fields withspreadIfDefined, which dropsnullas well asundefined, so those fields cannot be cleared through it. That silently made "remove the SSO domain" a no-op while the endpoint still answered{ ssoDomain: null }.ssoDomainandssoDomainVerificationnow usespreadIfNotUndefined, likethemeColors; any other field that needs clearing must switch the same way, and a test that reads the row back is the only thing that catches it.- On EE, a verified domain is owned by nobody.
verifiedDomainHooksis only set in the Cloud arm ofapp.ts, so CE and EE always getnullanddiscoverSignInMethodsreturns{ domainOwned: false }. On EE the single platform's settings apply to everyone, through/v1/flags. Turning domain ownership on for EE changes behaviour for existing installs (SAML-only setups without a verified domain would let passwords back in), so it needs its own decision. - Managed auth gated separately by
embeddingEnabled(signing keys). See the Managed Auth page. - The authn rate limiter (
core/security/rate-limit.ts) is registered withglobal: false— it protects NOTHING by default. Every public endpoint that sends email or does auth work must opt in per-route viaconfig.rateLimit(seeauthentication.controller.ts/otp-controller.tsfor theAPI_RATE_LIMIT_AUTHN_*pattern).
Key files
Entry point: assertPrinicpalAccessToProject (yes, misspelled in the source), exported from project-role/rbac-service.ts and called from core/security/v2/authz/authorize.ts on every project-scoped request.
packages/server/api/src/app/ee/authentication/— EE auth module root:saml-authn/,federated-authn/,otp/,enterprise-local-authn/,project-role/(RBAC service + middleware), andee-authorization.tsplan/ownership hookspackages/server/api/src/app/core/security/v2/authz/— where RBAC gets wired into request authorizationpackages/server/api/src/app/ee/managed-authn/— managed auth JWT exchange for the embedding SDKpackages/core/shared/src/lib/ee/authn/— shared enterprise authn exports, ACL types, verify-email and reset-password DTOspackages/core/shared/src/lib/ee/otp/— OTP model schema and theOtpTypeenumpackages/web/src/features/authentication/— sign-in form, third-party login buttons, verify email, reset password, auth hooks, managed auth clientpackages/web/src/app/routes/platform/security/sso/— SSO settings page, SAML dialog, allowed domains dialogpackages/web/src/app/routes/authenticate/— SAML ACS callback landing page
Paths verified 2026-07-17. An earlier version pointed at sso/oauth2-dialog.tsx; that file is gone and Google is now a plain googleAuthEnabled toggle on the SSO page, so it was dropped.