brain/wiki/connections-auth/managed-auth.md
Embedded authentication ("Embedding"): lets SaaS vendors embed the Activepieces builder in their own product. The vendor's backend signs a short-lived JWT with an RSA private key (from a Signing Key), passes it to the AP embed SDK, which calls POST /v1/managed-authn/external-token. The server verifies the JWT against the stored public key, auto-provisions/retrieves the user + project + limits from the claims, and returns a full AuthenticationResponse (with access token). Gated by platform.plan.embeddingEnabled (on the signing-key module, not the endpoint).
kid = Signing Key ID.sha256("managed_<platformId>_<externalUserId>") — managed users never have real emails.externalId.externalToken flow)externalTokenExtractor resolves the signing key by kid, verifies RS256, parses the payload.getOrCreateProject by (platformId, externalProjectId); creates a TEAM project owned by the platform owner if absent.applyProjectPieceAccess — assigns the project's named piece set (runs unconditionally every exchange, no managePiecesEnabled gate here).getOrCreateUser by (platformId, externalUserId) using the hashed email.EDITOR); issue a 7-day AP token.z.union ordered most-specific-first [v4, v3, v2] (v2 strips unknown keys and would otherwise swallow v3/v4):
version field): legacy nested pieces object.version: "v3"): flat piecesFilterType + piecesTags.version: "v4"): pieceSet required, is the piece set's key.securityAccess.public()) — the JWT signature is the security.pieceSet key (v4) → first legacy piecesTags entry matched against set key → platform Default set (with a warn log if no match). The project plan is not written.Entry point: managedAuthnModule, registered in packages/server/api/src/app/app.ts under the /v1/managed-authn prefix.
packages/server/api/src/app/ee/managed-authn/ — the whole feature: module, controller (single POST /external-token), service (provisioning + token issuance), and lib/external-token-extractor.ts (JWT verify, v2/v3/v4 payload parsing).packages/server/api/src/app/ee/signing-key/ — signing key CRUD and generation; this is where the embeddingEnabled plan gate sits.packages/core/shared/src/lib/ee/managed-authn/ — ManagedAuthnRequestBody and the shared wire contract.packages/web/src/features/authentication/api/managed-auth-api.ts — frontend API client used by the embed SDK integration.Paths verified 2026-07-17.