juniyasyos / auth-bridge-client
Laravel package for IAM SSO integration with JIT user provisioning
Requires
- php: ^8.1
- firebase/php-jwt: ^6.0
- illuminate/support: ^10.0|^11.0|^12.0
- spatie/laravel-permission: ^5.0|^6.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2026-04-26 11:46:32 UTC
README
Laravel package for IAM Single Sign-On (SSO), JWT verification, and JIT user provisioning.
Why use this package?
This package is designed for client applications that need to:
- authenticate users via IAM
- provision users automatically during login
- synchronize roles and application access
- verify tokens on every request
- support optional unit kerja sync
Highlights
- ✅ Minimal setup for a Laravel client
- ✅ IIS-compatible JWT verification
- ✅ JIT user provisioning from the IAM token
- ✅ Optional role sync with Spatie Permission
- ✅ Built-in IAM sync endpoints for user/role data
- ✅ Optional Livewire app switcher for current IAM applications
Requirements
- PHP
^8.1 - Laravel
^10.0 | ^11.0 | ^12.0 firebase/php-jwtspatie/laravel-permission(optional)
Quick setup
1. Install the package
composer require juniyasyos/auth-bridge-client
2. Publish config
php artisan vendor:publish --tag=iam-config
3. Run migrations
php artisan migrate
4. Set environment variables
IAM_ENABLED=true IAM_APP_KEY=your-app-key IAM_JWT_SECRET=your-jwt-secret IAM_BASE_URL=https://iam.example.com IAM_VERIFY_ENDPOINT=https://iam.example.com/api/verify IAM_PRESERVE_SESSION_ID=true IAM_SYNC_ROLES=true
5. Configure your User model
use Illuminate\Foundation\Auth\User as Authenticatable; use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable { use HasRoles; protected $fillable = [ 'iam_id', 'name', 'email', 'status', ]; }
Use
statusinstead ofactive. The package expectsstatusvalues likeactive,inactive, orsuspended.
6. Configure routes
The package already registers the main IAM routes automatically when enabled.
If you need protected pages, use middleware:
Route::middleware(['iam.auth:web'])->group(function () { Route::get('/dashboard', DashboardController::class); });
7. Add a login link
Use the built-in login route:
<a href="{{ route('iam.sso.login') }}">Login via IAM</a>
Configuration overview
Open config/iam.php and adjust the following sections.
SSO settings
iam.app_key— IAM application keyiam.jwt_secret— shared JWT secret for validating tokensiam.base_url— base URL of the IAM serveriam.login_route/iam.callback_route— local login/callback URLsiam.default_redirect_after_login— where to send users after loginiam.guard— auth guard used by default
User sync settings
iam.user_fields— map database columns to JWT claimsiam.identifier_field— primary field used to identify usersiam.sync_users— exposes/api/iam/sync-usersiam.sync_roles— enable role sync during provisioning
Token verification
iam.verify_each_request— validate token on every requestiam.attach_verify_middleware— automatically pushiam.verifyinto thewebmiddleware group
Unit Kerja sync (optional)
iam.unit_kerja_field— JWT claim name for unit/org dataiam.require_unit_kerja— reject login if unit/org is missingiam.sync_unit_kerja— syncunitKerjas()relation on the user modeliam.unit_kerja_model— model for unit/org records
Routes registered by the package
The package exposes these routes when enabled:
iam.sso.login— redirect user to IAM loginiam.sso.callback— handle callback and provisioningiam.logout— logout and clear IAM sessioniam.sync-users— IAM pulls client user dataiam.sync-roles— IAM pulls client role dataiam.push-roles— IAM pushes authoritative role updatesiam.push-users— IAM pushes user updates to clientiam.health— health check endpoint
Middleware aliases
iam.auth— ensures the user is authenticatediam.verify— verifies token on each requestiam.backchannel.verify— verifies IAM back-channel payload signatures
Usage steps for client apps
- Install the package and publish config.
- Run migrations.
- Set
IAM_ENABLED=true,IAM_APP_KEY,IAM_JWT_SECRET, andIAM_BASE_URL. - Confirm your
Usermodel hasiam_id,email,name, andstatus. - Protect routes with
iam.auth:web. - Add a login link using
route('iam.sso.login'). - If needed, publish views for customization:
php artisan vendor:publish --tag=iam-views
Example token payload
IAM should send a JWT payload like:
{
"type": "access",
"app_key": "your-app-key",
"sub": 123,
"name": "John Doe",
"email": "john@example.com",
"nip": "123456",
"roles": [{"slug": "admin"}],
"unit_kerja": ["Finance", "IT"],
"exp": 1234567890
}
Custom field mapping
Update config/iam.php:
'user_fields' => [ 'iam_id' => 'sub', 'name' => 'name', 'email' => 'email', 'nip' => 'nip', 'nik' => 'nik', ], 'identifier_field' => 'iam_id',
Events
A successful login dispatches the IamAuthenticated event. Use it for auditing or custom actions.
use Juniyasyos\IamClient\Events\IamAuthenticated; Event::listen(IamAuthenticated::class, function ($event) { // $event->user // $event->payload // $event->guard });
License
MIT
'guards' => [ 'web' => [ 'guard' => 'web', 'redirect_route' => '/', 'login_route_name' => 'login', 'logout_redirect_route' => 'home', ], ],
To add a new guard, register your own route and set `defaults('guard', 'your_guard')` or pass the guard parameter to the controller.
## Event Hooks
A successful login dispatches the `IamAuthenticated` event. Listen to this event for auditing, downstream provisioning, or custom logging.
```php
use Juniyasyos\IamClient\Events\IamAuthenticated;
Event::listen(IamAuthenticated::class, function ($event) {
// $event->user, $event->payload, $event->guard
});
License
MIT