PHP code example of madbox-99 / laravel-user-team-sync
1. Go to this page and download the library: Download madbox-99/laravel-user-team-sync library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
madbox-99 / laravel-user-team-sync example snippets
'client' => [
// This app's own key. Must equal sync_apps.name on the publisher and the
// slug of the plan category that grants access to this app. A login is
// refused when this key is absent from the token's `apps` claim.
'app_key' => env('IDENTITY_APP_KEY'),
'identity_url' => env('IDENTITY_URL'),
'client_id' => env('IDENTITY_CLIENT_ID'),
'client_secret' => env('IDENTITY_CLIENT_SECRET'),
'redirect_uri' => env('IDENTITY_REDIRECT_URI'),
'scopes' => '',
'http_timeout' => env('IDENTITY_HTTP_TIMEOUT', 10),
// Kept short: the revalidation middleware runs on every authenticated
// page, so a hanging connect would otherwise pin a worker and the
// session lock for the full read timeout, request after request.
'http_connect_timeout' => env('IDENTITY_HTTP_CONNECT_TIMEOUT', 3),
// Re-fetch the claims once the session's last check is older than this.
'revalidate_after_minutes' => env('IDENTITY_REVALIDATE_MINUTES', 15),
// How long a session survives while the identity provider is unreachable.
'grace_hours' => env('IDENTITY_GRACE_HOURS', 24),
// How long to wait before retrying an unreachable provider. Without it
// every request would retry, so a slow provider would cost every page
// load the full HTTP timeout for the whole grace window.
'retry_after_minutes' => env('IDENTITY_RETRY_MINUTES', 5),
// Comma-separated e-mails. Non-empty during a phased rollout: only these
// users go through SSO, everyone else keeps using the legacy login and
// the legacy push. Empty means everyone goes through SSO.
'allowlist' => array_values(array_filter(array_map('trim', explode(',', (string) env('IDENTITY_SSO_ALLOWLIST', ''))))),
// Keeps the legacy receiver endpoints mounted while both worlds run
// side by side. Turn off once the rollout is complete.
'legacy_receiver' => env('IDENTITY_LEGACY_RECEIVER', true),
// Maps a token role name onto a local role name. Honoured on both role
// drivers — see "Translating roles" below.
'role_map' => [],
// Where to send a user who authenticated but has no subscription
// covering this app.
'subscribe_url' => env('IDENTITY_SUBSCRIBE_URL'),
// Where to send a user back to retry signing in after a failed or
// refused callback. Defaults to this app's own login page, since a
// phased rollout keeps the legacy password form available as a
// fallback for exactly this case.
'login_url' => env('IDENTITY_LOGIN_URL', '/login'),
],
// This automatically triggers sync to all receiver apps
$user->update(['role' => 'admin']);
use Madbox99\UserTeamSync\Facades\UserTeamSync;
// Create a user on all receiver apps
UserTeamSync::createUser(
email: '[email protected]',
name: 'John Doe',
password: 'plain-text-password', // hashed automatically before sending
role: 'editor',
ownerEmail: '[email protected]',
);
// Sync user changes
UserTeamSync::syncUser('[email protected]', [
'new_email' => '[email protected]',
'role' => 'admin',
]);
// Create a team on all receiver apps
UserTeamSync::createTeam(
teamName: 'Marketing',
userEmail: '[email protected]',
slug: 'marketing', // optional, auto-generated from name
);
// Toggle user active status on a specific app
UserTeamSync::toggleUserActive(
userEmail: '[email protected]',
isActive: true,
appKey: 'crm',
);
// In EventServiceProvider or listener
use Madbox99\UserTeamSync\Events\UserCreatedFromSync;
class HandleSyncedUser
{
public function handle(UserCreatedFromSync $event): void
{
// $event->user
}
}
use Madbox99\UserTeamSync\Concerns\HasSuperAdmin;
class User extends Authenticatable
{
use HasSuperAdmin; // isSuperAdmin(), setSuperAdmin(), grantSuperAdmin(), revokeSuperAdmin(), superAdmins()
}
use Madbox99\UserTeamSync\Filament\SuperAdminColumn;
use Madbox99\UserTeamSync\Filament\SuperAdminToggle;
SuperAdminToggle::make(), // form
SuperAdminColumn::make(), // table