Download the PHP package madbox-99/laravel-user-team-sync without Composer

On this page you can find all versions of the php package madbox-99/laravel-user-team-sync. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-user-team-sync

Laravel User Team Sync

Laravel package for synchronizing users and teams across multiple Laravel applications using a Publisher/Receiver pattern.

Requirements

Installation

Then run the install command:

This will:

Manual Installation

If you prefer to install manually:

Then add these to your .env:

Configuration

Modes

Mode Description
publisher Sends sync events to other apps
receiver Receives sync events from a publisher
both Sends and receives
client Delegates authentication to a central identity provider instead of receiving pushed user/team data

Publisher Setup

Set mode to publisher. Receiver apps can be stored in the config file or in the database.

Option A: Config-based apps (default)

Define apps in config/user-team-sync.php:

Option B: Database-based apps (recommended)

Store apps in the sync_apps table for dynamic management:

The install command (php artisan user-team-sync:install) can set this up interactively, or you can manage apps manually:

API keys are stored using Laravel's encrypted cast. Make sure your APP_KEY is set.

Receiver Setup

Set mode to receiver and configure the API key:

The receiver API key must match the publisher's key for that app.

Client mode (SSO)

Set mode to client to stop receiving pushed user/team data and instead authenticate users against a central Laravel Passport identity provider, rebuilding this app's local state from the token's claims on every login and on every revalidation.

Translating roles

The identity provider sends one lower-case role name per login (admin, manager, subscriber). client.role_map translates it onto whatever this app calls that role, and it applies whichever receiver.role_driver is set — Spatie roles and a plain users.role column alike.

How a claim role is resolved:

Driver 1. role_map hit 2. no hit 3. still nothing
spatie the mapped role name a real local role whose name matches case-insensitively receiver.default_role
anything else (plain users.role column) the mapped value the claim role, verbatim — unreachable

The two drivers differ in step 2 on purpose. Under Spatie the roles table lists the app's vocabulary, so an unknown claim role can be recognised by spelling or sent to default_role. A plain column publishes no vocabulary — the package does not introspect enum casts or CHECK constraints — so the only value it knows the column accepts is the one the publisher already sends. It is therefore written through unchanged, and default_role never applies on that path.

The practical consequences:

Local-only roles

Some roles are granted by hand in one app and are unknown to the identity provider — typically a Filament Shield Super-Admin. List them in receiver.local_only_roles:

Every path that writes a role — the SSO login and revalidation, /api/create-user and /api/sync-user — then honours two rules:

Names are compared exactly, in PHP. Grant or revoke a local-only role in the app itself (assignRole() / removeRole(), or the app's own user admin). The host User model needs no override of syncRoles() for this.

Changed in the next release. Before it, role_map was consulted only on the Spatie path; the column path wrote the raw claim role and ignored the map entirely. Apps whose local vocabulary equals the publisher's see no behaviour change — an unmapped role still passes through verbatim.

Routes

Method Route Name Purpose
GET /auth/redirect identity.redirect Starts the OAuth authorization-code + PKCE handshake with the identity provider
GET /auth/callback identity.callback Exchanges the code for tokens, fetches claims, provisions the local user, and signs them in

Point your login link at route('identity.redirect') (it accepts an optional ?intended= relative path to return to after login). Both routes are registered automatically under the web middleware group when mode is client — nothing else to add to routes/web.php.

Callback failure pages

/auth/callback renders a package view instead of a raw framework error for every failure it can distinguish from a forged or stale request. Each page uses only __() strings — translate them by publishing a JSON translation file — and none of them render a token, a client secret, a claims payload, or an exception message.

Situation Status View Notes
The identity provider is unreachable, erroring, or answers with a malformed payload (IdentityUnavailableException) 503 identity.unavailable Transient. The message invites the user to try again shortly; links to client.login_url.
The provider answers and refuses the code or token (IdentityRejectedException) 401 identity.rejected An authentication failure, not an outage. Invites a retry; links to client.login_url. Sends a WWW-Authenticate: Bearer realm="<identity_url>" header, as RFC 7235 requires on every 401 — harmless for this interactive HTML page, but conformant.
The claims cannot be reconciled with local data, e.g. an e-mail already held by a different local identity (IdentityConflictException) 409 identity.conflict The user cannot fix this themselves — the page asks them to contact support and deliberately never prints the colliding e-mail address or any other claim data.
The callback's state does not match this session's handshake, or the user authenticated but is not on client.allowlist 403 identity.refused Both causes render the exact same response — status, body, and headers — on purpose: at the response level nothing distinguishes them, so an attacker cannot probe which e-mail addresses are allowlisted by reading what a callback sends back. Links to client.login_url.
The user authenticated but has no subscription covering this app 200 identity.not-entitled Unchanged from before — see client.subscribe_url.

In every refusal path the PKCE handshake (identity.state, identity.code_verifier, identity.intended) is cleared before the response is built, exactly as it already was for a mismatched state — a friendlier page must never leave a reusable handshake behind.

The 403 response is identical, but the two paths that reach it are not equal-time. A mismatched state is rejected immediately. A not-allowlisted user is rejected only after the callback has already made two real outbound calls to the identity provider (exchangeCode then fetchClaims), so the second path is measurably slower. This is a known, accepted gap, not an oversight: exploiting it requires an attacker's own valid state/code pair — i.e. their own handshake, initiated from their own login attempt — which does not obviously extend into a way to learn other people's e-mail addresses against the allowlist. It is not closed, and it should be revisited if that assumption ever stops holding (for example if authorization codes became replayable, or another actor could otherwise reach the not-allowlisted branch without completing a real handshake of their own).

Keeping sessions self-healing: RevalidateIdentity

Signing in only provisions the user once. To pick up a team rename, a new membership, a role change or a cancelled subscription without any push from the publisher, add Madbox99\UserTeamSync\Client\Http\Middleware\RevalidateIdentity to your app's authenticated middleware stack — for a Filament panel, its authMiddleware():

On every request past a fresh CHECKED_AT (older than revalidate_after_minutes), the middleware:

  1. Re-fetches the claims from /api/userinfo. A 401 first retries once with the refresh token — an aged-out access token is not the same thing as revoked access — and only logs the user out if the refresh also fails.
  2. Re-runs IdentityProvisioner, so a renamed team, an added/removed membership or a role change lands locally within one revalidate_after_minutes window.
  3. Logs the user out if this app's app_key has disappeared from the token's apps claim — this is how a cancelled subscription takes effect fleet-wide with no push.
  4. Treats a 5xx/unreachable provider — or a 2xx whose body is not a well-formed claims payload, such as a maintenance page served mid-deploy — as an outage, not as revoked access: the session survives for up to grace_hours and only logs out once the grace window is exhausted. Collapsing this distinction would turn a five-minute identity-provider outage into a forced logout across every app in the fleet.
  5. Retries a failing provider at most once per retry_after_minutes rather than on every request, so a slow provider does not add its timeout to every page load for every user. The grace window still runs from the first failure, so a long outage expires on schedule.
  6. Never lets an unexpected error escape: anything other than a deliberate rejection or an unreconcilable conflict is logged and tolerated rather than 500-ing the page.

The middleware only touches sessions that were established through SSO. During a phased rollout (see allowlist) the same app still signs other users in through the ordinary password form; those sessions carry no identity token and are passed through untouched.

SSO logins deliberately mint no "remember me" cookie. A recaller cookie outlives the session and would re-authenticate the user into a fresh session holding no identity state, which the middleware passes through by design — permanently exempting anyone who idles past SESSION_LIFETIME from revalidation. After the session lapses the user is sent back through the identity provider instead, which for an already-signed-in user is a transparent round trip.

Operational note: malformed claims count as an outage

A 2xx response whose body is not a well-formed claims payload is treated exactly like an unreachable provider, not like a bad request. That covers a maintenance or proxy error page served with HTTP 200, but also a genuine data-quality fault on the provider side: an orgs entry with an empty slug or name, or a user with an empty name.

What that looks like in practice: affected sessions keep working for grace_hours and then log out silently, instead of the page erroring loudly. The trade is deliberate — a fleet-wide 500 on every page of every module app is the worse failure — but it means a provider-side data fault is quiet, so watch the logs rather than waiting for user reports:

Usage

Automatic Sync (Observer)

When auto_observe is enabled (default), the package automatically watches your User model for changes to configured fields (email, role by default) and syncs them to all active receiver apps.

Manual Sync via Facade

API Endpoints (Receiver)

All endpoints are protected by Bearer token authentication.

Method Endpoint Description
POST /api/create-user Create a new user
POST /api/sync-user Update user fields
POST /api/toggle-user-active Set active/inactive status
POST /api/create-team Create a team
POST /api/update-team Apply a team rename (see below)
POST /api/remove-team-member End a user's team membership (see below)
GET /api/user-teams Get user's teams
POST /api/sync-password Sync password hash
GET /api/identity-audit Diff users/teams/memberships against the publisher
POST /api/identity-uuids Bulk-apply the publisher's uuid mapping

Team renames

Receivers used to match teams by slug forever after creation, so renaming a team on the publisher silently and permanently broke the cross-app link. TeamSyncObserver now propagates changes to the fields in publisher.team_sync_fields (default name, slug) via UpdateTeamJob.

/api/update-team identifies the team by uuid. It falls back to original_slug — the team's pre-rename slug, which is what the receiver still knows it by — only when the local team has no uuid of its own, and then adopts the publisher's uuid so the next rename skips the fallback. A local uuid that differs from the incoming one means the two sides disagree about which team this is; that returns 409 rather than renaming the wrong team.

A 404 is normal, not an error: the publisher fans out to every active app regardless of entitlement, so most apps do not know most teams. Those are logged with status skipped.

Removing a team member

RemoveTeamMemberJob ends one membership on one app:

POST /api/remove-team-member payload: user_email (required), team_slug (required), user_uuid and team_uuid (optional). The receiver detaches the user from the team; the account itself is never deleted or deactivated. Matching is uuid first, then email / slug; a differing local uuid returns 409. An already-ended membership returns 200 with removed: false; an unknown user or team returns 404 (logged as skipped). A pending attachment for the pair is always dropped, and a users.team_id primary-team column pointing at the removed team is moved to the lowest remaining team, or NULL.

Events

Listen to these events for custom logic:

Event When
UserCreatedFromSync User created on receiver
UserSynced User fields updated
PasswordSynced Password synced to receiver
UserActiveToggled Active status changed
TeamCreatedFromSync Team created on receiver
TeamUpdatedFromSync Team renamed on receiver
TeamMemberRemovedFromSync User detached from a team on receiver
TeamSynced A receiver accepted a team change
TeamSyncFailed A receiver rejected a team change (a 404 does not count)
SyncFailed Any user sync operation failed

Logging

All sync operations are logged to the sync_logs table. Configure in config/user-team-sync.php:

Environment Variables

Variable Description Default
USER_TEAM_SYNC_MODE Sync mode receiver
USER_TEAM_SYNC_API_KEY API key for authentication —
USER_TEAM_SYNC_APP_SOURCE App storage: config or database config
USER_TEAM_SYNC_USER_MODEL User model class App\Models\User
USER_TEAM_SYNC_TEAM_MODEL Team model class App\Models\Team
USER_TEAM_SYNC_QUEUE Queue name for jobs default
USER_TEAM_SYNC_QUEUE_CONNECTION Queue connection null
USER_TEAM_SYNC_TRIES Job retry attempts 3
USER_TEAM_SYNC_BACKOFF Seconds between retries 60
USER_TEAM_SYNC_TIMEOUT HTTP timeout in seconds 10
IDENTITY_APP_KEY This app's key in the apps claim (client mode) —
IDENTITY_URL Identity provider base URL (client mode) https://cegem360.eu
IDENTITY_CLIENT_ID OAuth client ID (client mode) —
IDENTITY_CLIENT_SECRET OAuth client secret (client mode) —
IDENTITY_REDIRECT_URI OAuth redirect URI, must match /auth/callback (client mode) —
IDENTITY_HTTP_TIMEOUT HTTP timeout in seconds for identity provider calls 10
IDENTITY_REVALIDATE_MINUTES Minutes before RevalidateIdentity re-checks the session 15
IDENTITY_GRACE_HOURS Hours a session survives while the identity provider is unreachable 24
IDENTITY_SSO_ALLOWLIST Comma-separated e-mails allowed through SSO during a phased rollout — (everyone)
IDENTITY_LEGACY_RECEIVER Keep legacy receiver endpoints mounted alongside client mode true
IDENTITY_SUBSCRIBE_URL Where to send an authenticated user with no entitlement for this app https://cegem360.eu
IDENTITY_LOGIN_URL Where to send the user back to retry after a failed or refused callback /login

Testing

License

MIT License. See LICENSE for details.

Global super admin

A tenant-independent super admin flag, local to each app — the SSO sync never sends, grants or removes it.

Super admins pass every Gate / policy check (user-team-sync.super_admin.gate_bypass, default true).

With Filament, add the field and column to the user resource — both are visible to super admins only, and nobody can change their own flag:


All versions of laravel-user-team-sync with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
laravel/framework Version ^11.0 || ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package madbox-99/laravel-user-team-sync contains the following files

Loading the files please wait ...