Introducing a new way to review your PRs.

Read the announcement

ever-co / ever-gauzy

Ever® Gauzy™ - Open Business Management Platform (ERP/CRM/HRM/ATS/PM) - https://gauzy.co

View on GitHub

27 documents · Updated Nov 23, 2026

docs / embedded-client-access

Embedded client access

Embedded client access lets another site use Gauzy's timer without receiving broad API access. It supports two trust paths: a host backend exchanges an organization credential, or a person approves a site from the Gauzy web app. Both paths create a short-lived timer token bound to a member, organization, origin, and optional client.

Access model

The access model separates host trust from person-approved browser use. Credential exchange suits a product with its own backend. Site grants suit a browser site where the person gives consent through Gauzy.

Credential exchange

An organization administrator creates a credential for a host backend. The secret is shown only once and the service keeps a digest. A credential can cover the organization or one client. It can also allow the host to add a new employee member when an exchange names a valid address and no active member exists.

The host sends the credential with a member identity and page origin. The service checks the credential, organization, origin, member status, and time-tracking permission before it returns a timer token. A client-limited credential keeps timer use and client reports inside that client. Refused credential attempts are limited by source address so repeated bad exchanges do not cause unlimited credential lookups.

References: packages/…/embed-credential.service.ts• L181-229 packages/…/embed-credential.service.ts• L284-327 packages/…/embed-credential.service.ts• L434-512 packages/…/embed-credential.service.spec.ts• L279-341 packages/…/embed-credential.service.spec.ts• L501-604

Site grants

A site grant is a person's approval for one site to start and stop that person's timer. The person must use a first-party Gauzy session. The service checks the approved origin and the person's active membership and time-tracking permission before it returns a timer token and a renewal token.

Each renewal token works once. A successful renewal spends it and creates its successor for the same site and grant family. Reuse of a spent token ends the whole family. A person or an organization administrator can revoke the family. Existing timer tokens remain usable until their short expiry, but no further renewal can succeed.

References: packages/…/embed-site-grant.service.ts• L155-185 packages/…/embed-site-grant.service.ts• L187-204 packages/…/embed-site-grant.service.ts• L228-291 packages/…/embed-site-grant.service.ts• L330-350 packages/…/embed-site-grant.service.sqlite.spec.ts• L301-433 packages/…/embed-site-grant.service.sqlite.spec.ts• L436-540

Token scope

Both paths issue the same kind of signed access token. The token carries the member, tenant, organization, origin, source credential or grant, and optional client. Its permissions are limited to timer use and the data needed by the embedded timer. It is not a normal user session and cannot open general API routes.

The timer token uses GAUZY_EMBED_TOKEN_TTL_SECONDS. The default is 15 minutes and the service caps the value at one hour. Site renewal lasts 30 days, but it only produces another timer token while the grant, origin, and member checks still pass.

References: packages/…/embed-member-token.ts• L25-47 packages/…/embed-member-token.ts• L63-108 packages/…/embed-site-grant.service.ts• L395-425 packages/…/embed-credential.service.spec.ts• L279-297 packages/…/embed-site-grant.service.sqlite.spec.ts• L301-345

Origin management

An origin is the browser scheme, host, and port. Organizations manage approved origins, and the normalized origin is the common control used by credential exchange, site authorization, renewal, and embed CORS.

Allowed origins

An administrator adds an exact origin such as https://app.example.com. A path or wildcard is not an origin. The organization can allow an origin for backend credential exchange while keeping direct person sign-in off through allowPersonSignIn.

Turning person sign-in off blocks new authorization and renewal. Removing the origin blocks new exchanges and site access checks. Tokens already issued continue only until their normal short expiry.

References: packages/…/embed-credential.service.ts• L482-505 packages/…/embed-site-grant.service.ts• L382-393 packages/…/embed-site-grant.service.sqlite.spec.ts• L362-394 packages/…/embed-site-grant.service.sqlite.spec.ts• L566-592

CORS enforcement

CORS is checked before a request has a tenant context. For embed routes, the API therefore asks whether any organization allows the normalized browser origin. This browser check permits only the embed route family and does not make the organization origin a general API origin.

The request still needs a valid credential, grant, or timer token after CORS succeeds. Embed tokens use a header or request body, so embed CORS does not enable browser credentials.

This flow shows how an origin moves from the browser request to the timer response.

flowchart TD
    A[Browser request with Origin] --> B{General API origin?}
    B -- Yes --> C[Use normal API CORS policy]
    B -- No --> D{Embed route?}
    D -- No --> C
    D -- Yes --> E{Any organization allows origin?}
    E -- No --> F[Reject embed CORS]
    E -- Yes --> G[Allow embed CORS]
    G --> H{Credential, grant, or timer checks pass?}
    H -- No --> I[Reject request]
    H -- Yes --> J[Return timer response]

References: packages/…/embed-cors.ts• L5-59 packages/…/embed-allowed-origin.service.ts• L138-205 packages/…/embed-site-grant.service.ts• L228-243 packages/…/embed-site-grant.service.sqlite.spec.ts• L494-509

Authentication boundary

The embed access model sits inside the normal API authentication boundary. A global embed guard recognizes an embed token and limits it to declared timer routes. Normal JWT loading and permission checks then apply the member and organization context.

Member eligibility

The service issues a timer token only for an active, unarchived employee with an account, active organization membership, enabled time tracking, and a role with the time-tracker permission. The same checks run during site renewal, so a later member or role change can stop future token renewal.

When a credential may add members, the new address must pass the platform's member rules. The resulting account has the employee role, no password, and time tracking enabled. It does not receive a welcome message. Concurrent exchanges for the same new address produce one member rather than duplicate members.

References: packages/…/embed-member-token.ts• L41-79 packages/…/embed-member-token.ts• L126-175 packages/…/embed-member.service.sqlite.spec.ts• L368-500 packages/…/embed-member.service.sqlite.spec.ts• L584-614

Route scope

The token can reach only the routes needed by the embedded timer. These routes provide member and role data, usable projects, timer state, and timer start or stop. Server-side rules reject timer starts outside a credential's client scope and prevent the caller from supplying server-controlled time fields.

The access boundary has two distinct proofs. Credential exchange and client reports use the presented host credential. Site authorization uses a first-party Gauzy session. Site renewal and sign-out use the renewal token, but the renewal token never becomes a general API session.

References: packages/…/embed-member-token.ts• L90-108 packages/…/embed-site-grant.service.ts• L161-177 packages/…/embed-site-grant.service.ts• L213-225 packages/…/embed-site-grant.service.ts• L428-461

Authentication outcomes

The response code identifies which trust check failed. A malformed, unknown, revoked, expired, or reused proof returns an authentication failure. A valid proof with a disallowed member, origin, client, or route returns a permission failure. Rate limits protect repeated refused credential attempts. Database outages remain service failures rather than looking like bad credentials.

Credential revocation is visible to token checks within the revocation cache window. Site-grant revocation ends renewal for the family, while already issued timer tokens finish only until their expiry.

References: packages/…/embed-credential.service.ts• L232-273 packages/…/embed-credential.service.ts• L367-423 packages/…/embed-site-grant.service.ts• L479-493 packages/…/embed-site-grant.service.postgres.spec.ts• L212-312

Persistence model

Persistence stores the state needed to scope, revoke, and renew embedded access. Clear credentials and renewal tokens are not stored. The records are also not part of data export, so export does not move working access to another server.

Access records

The records have separate responsibilities:

RecordPurposeImportant lifetime rule
Embed credentialGives a host backend organization or client accessRevocation stops new exchanges; a deleted client makes its client-scoped access unusable
Allowed originLists an organization's approved browser originThe normalized origin is unique within an organization
Site grantStores one person's renewal chainAll rows in a family represent one sign-in and a revoked family cannot renew

The site-grant family supports replay protection. Each renewal creates a new row, while the prior row becomes used. Reuse or concurrent use of a spent row revokes the family.

References: packages/…/embed-credential.service.ts• L190-208 packages/…/embed-site-grant.service.ts• L399-425 packages/…/embed-site-grant.service.ts• L442-477 packages/…/embed-site-grant.service.sqlite.spec.ts• L511-540

Persistence migrations

The schema grows through additive migrations for credentials, allowed origins, and site grants. Later migrations add client scope, member-add permission, and person-sign-in control. New fields must use safe defaults so older records do not gain access by accident.

The persistence contract spans entity rules, indexes, foreign keys, migration defaults, and supported database paths. Site-grant renewal and revocation also depend on atomic writes and row-level ordering, which the PostgreSQL concurrency checks verify.

References: packages/…/embed-site-grant.service.postgres.spec.ts• L28-44 packages/…/embed-site-grant.service.postgres.spec.ts• L212-312 packages/…/embed-member.service.sqlite.spec.ts• L202-329 packages/…/embed-site-grant.service.sqlite.spec.ts• L183-240

Change checklist

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

  • Keep origin normalization identical for exchange, authorization, renewal, and CORS lookup.
  • Keep token claims aligned across credential exchange, site grants, JWT loading, route guards, and client scope checks.
  • Keep member eligibility aligned for initial exchange, member addition, authorization, renewal, and timer routes.
  • Keep one-use renewal updates and family revocation atomic across SQLite and PostgreSQL behavior.
  • When changing persisted access fields, update entity rules, migration defaults, uniqueness, foreign keys, and export exclusion together.
  • When changing credential refusal or revocation timing, review both address throttling and the revocation cache.

Important failure modes

TriggerConsequenceGuard
The browser origin is not approvedCORS or token issuance failsAdd the exact normalized origin to the organization
Person sign-in is off for the originAuthorization and renewal fail, but current timer tokens can finishUse backend credential exchange or enable person sign-in
A credential is revokedNew exchanges fail after the revocation cache windowExchange only with a new credential
A renewal token is reused or sent from another originRenewal fails; reuse ends the grant familyKeep the token private and renew from its issued origin
The member loses active status or time-tracker permissionAuthorization or renewal failsRestore member eligibility before issuing more access
A client-scoped credential targets another client's projectTimer start or client report is refusedUse resources inside the credential's client scope
A migration omits a safe default or database-specific ruleScope or revocation behavior becomes inconsistentCheck all supported database migration paths before enabling access

Key files

FileWhy to read it
packages/…/embed-credential.service.tsDefines host credential creation, exchange, member addition, client reports, throttling, and revocation
packages/…/embed-site-grant.service.tsDefines person approval, one-use renewal, sign-out, listing, and family revocation
packages/…/embed-member-token.tsDefines shared member eligibility and timer-token claims
packages/…/embed-allowed-origin.service.tsDefines origin approval and the cross-organization origin lookup used by CORS
packages/…/embed-cors.tsConnects approved origins to the browser CORS boundary
packages/…/embed-member.service.sqlite.spec.tsShows the member rules and safe account creation behavior through platform commands
packages/…/embed-site-grant.service.sqlite.spec.tsShows site authorization, renewal replay protection, scope checks, and revocation behavior
packages/…/embed-site-grant.service.postgres.spec.tsShows the concurrency contract for renewal and family revocation
packages/…/1791000019400-CreateEmbedCredentialTable.tsShows the base host-credential persistence contract
packages/…/1791000019500-CreateEmbedAllowedOriginTable.tsShows the allowed-origin persistence and uniqueness contract
packages/…/1791000019860-CreateEmbedSiteGrantTable.tsShows the site-grant family and renewal persistence contract