Download the PHP package padosoft/laravel-iam-client without Composer
On this page you can find all versions of the php package padosoft/laravel-iam-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download padosoft/laravel-iam-client
More information about padosoft/laravel-iam-client
Files in padosoft/laravel-iam-client
Package laravel-iam-client
Short Description Client Laravel per app che consumano Laravel IAM: login OIDC, verifica JWT/JWKS, introspection, middleware iam.auth/iam.can, Gate adapter, policy cache, webhook receiver.
License MIT
Informations about the package laravel-iam-client
Laravel IAM — Client
The drop-in Laravel client for apps that delegate authorization to a Laravel IAM server.
iam.can / iam.auth middleware, a Gate adapter so $user->can() just works, decision caching — fail-closed by design.
Why this package
Laravel IAM centralizes who can do what into one Policy Decision Point
(PDP): RBAC + ABAC + ReBAC, step-up assurance, tenant isolation, tamper-evident audit. But your consuming
apps shouldn't have to learn any of that — they already speak Laravel: middleware, Gate, policies,
$user->can().
laravel-iam-client is the bridge. You point it at your IAM server, and authorization decisions flow
through the tools your app already uses:
It works in two modes with identical app code: local (the IAM server lives in the same app — the
client calls the PDP in-process, zero network) or http (remote server — the client calls the Admin API).
Swap a single env var to move from a modular monolith to a distributed deployment.
Fail-closed, always. Every transport (
LocalDecider,HttpDecider) denies on any error — unreachable PDP, non-2xx, unparseable body, engine exception. There is no fail-open opt-out: an outage never opens the doors.
Features
iam.can:<permission>middleware — a drop-in replacement for Spatie'spermission:middleware, decided by the central PDP. Bind a route parameter (iam.can:billing:invoices.update,invoice) and the decision is scoped to that resource — including through route-model binding.iam.authmiddleware — fail-closed guard that 401s any request without a resolvable subject.- Gate adapter — registers
Gate::beforeso$user->can('billing:invoices.update'),@canBlade directives andauthorize()in controllers all consult IAM. By default it only intercepts namespaced abilities (those containing:), leaving your local Gates/policies untouched. - Pluggable transports (
Decider) —LocalDecider(in-process PDP),HttpDecider(remote Admin API), both fully fail-closed. Your app code never knows which is in use. CachingDecider— decisions are deterministic per input, so they're cached for a short TTL;explainqueries are never cached.- Step-up aware — a permit that requires a higher assurance level (
requiresStepUp) is treated as not yet granted by middleware and the Gate adapter (IamDecision::granted()), so you can't accidentally let a low-AAL session through. Iamfacade —Iam::can($user, 'warehouse:stock.adjust', ['amount' => 300])for ABAC checks with context.- Delegated access (AI agents), act-aware — verify RFC 8693 delegated tokens (
sub= user,act= agent) via mandatory introspection, decide withIam::checkDelegated()/ theiam.can.delegatedmiddleware, and never cache a delegated decision: effective authority is always the fresh strict intersection user ∩ agent, revocation included.
Use cases
- Protect routes against a central policy. Replace scattered role checks with
->middleware('iam.can:hr:salaries.view')— the rule lives in IAM, not in your app. - Keep using Laravel's authorization API.
@can,$user->can(), policies andauthorize()keep working; the answer just comes from the central PDP. - Per-resource (ReBAC) checks.
iam.can:projects:edit,projectbinds the decision to the bound{project}— "can this user edit this project", not the permission in the abstract. - Go from monolith to services without rewriting. Start with
mode=local(same app), flip tomode=httpwhen you extract the IAM server — the controllers don't change.
Installation
Publish the config:
Requirements: PHP 8.3+, Laravel 11/12+. Depends on
padosoft/laravel-iam-contracts.
Quick start
1. Configure the transport
config/iam-client.php (publish it, then set env):
That's it — the service provider wires the right decider (with caching) and registers the middleware aliases and the Gate adapter automatically.
Use
httpsin production (fail-closed). Credentials and the Bearer-carrying decision call never travel over plainhttp://: a non-httpsIAM_CLIENT_BASE_URL/IAM_CLIENT_OAUTH_URL(except loopback —localhost/127.0.0.1/::1) is denied rather than sending a secret or token in clear. SetIAM_CLIENT_ALLOW_INSECURE=trueto lift this for local development only.
Authentication modes (choose one)
The SDK authenticates to the PDP in one of three ways (checked in this order of precedence):
-
private_key_jwt— asymmetric, no shared secret (strongest): give the SDK yourclient_idand an ES256 private key; it signs a short-lived assertion per token request and exchanges it for an access token — nothing secret ever leaves your app, nothing to rotate. Register the matching public key (JWKS) in IAM. Takes precedence over everything else.Full guide: private_key_jwt.
-
Self-managed
client_credentials: give the SDK your OAuthclient_id+client_secretand it mints and refreshes the token itself, and — when IAM auto-rotates the secret — it self-fetches the new one (during the grace) and hot-swaps it, so the service never breaks on a rotation and you never touch a secret by hand.The rotated secret is cached (in your cache store) on pickup; enable IAM's self-fetch endpoint server-side with
IAM_OAUTH_CLIENT_SELFFETCH=true. See Application credentials & lifecycle. - Static token (default): you supply a service bearer token via
IAM_CLIENT_TOKEN, obtained out of band.
2. Protect routes with iam.can
iam.auth ensures there's a resolvable subject (401 otherwise); iam.can denies with 403 when IAM says
no — or when a step-up is required but not yet satisfied.
3. Use the Gate adapter (your existing code keeps working)
4. Ask IAM directly with the facade
5. Declare your permissions/roles: push a manifest
Apps that don't use spatie/laravel-permission declare their permission catalog + roles in a manifest file (versioned in your repo — it is your source of truth). Push it to IAM whenever it changes:
It submits to IAM's Admin API (authenticated with this client's own bearer — the token needs
iam:manifests.submit). IAM diffs it: additive changes apply, a removal is gated for approval in the
console and the removed role/permission is deprecated (kept for history, disabled), never deleted. Run it
in CI on deploy for hands-off sync. See
Keeping IAM in sync.
Delegated access: when an AI agent acts for a user
With the laravel-iam-agents module on the server, an
agent never receives a user's token: it exchanges it (OAuth 2.0 Token Exchange, RFC 8693) for a
short-lived delegated token carrying BOTH identities — sub = the user, act = the agent. This client is
the enforcement half:
Three properties are non-negotiable and built in: a malformed delegated token throws (it never degrades
to a single-subject check), delegated decisions are never cached (revocation freshness beats the extra
round-trip), and the typ: delegated+jwt header is hygiene — the defence is server-side introspection.
This client is also the exchange half when your app is itself a registered agent (an orchestrator, a
flow-ai runtime): TokenExchanger performs the RFC 8693 call, authenticating with the same
private_key_jwt config (http.client_id + http.private_key — an agent has ONE identity):
And every request that passes iam.can.delegated hydrates Laravel Context: logs emitted downstream
(and queued jobs, via Context's automatic dehydrate/hydrate) carry iam_delegation — sub, the act
chain, the grant id — so cross-package audit queries ("everything agent X did, for anyone") join for free.
How it fits the ecosystem
| Package | Role |
|---|---|
| laravel-iam-contracts | Shared interfaces & DTOs — the dependency root |
| laravel-iam-server | The IAM server: identity, PDP, OAuth/OIDC, audit, governance, Admin API & panel |
| laravel-iam-client (this repo) | Consumer SDK: iam.can/iam.auth middleware, Gate adapter, decision caching |
| laravel-iam-ai | Optional AI module: advisory-only governance (redaction + hallucination guard + audit) |
| laravel-iam-directory | Optional directory module: LDAP / Active Directory (LdapRecord); SCIM in v2 |
| laravel-iam-bridge-spatie-permission | Migration bridge from spatie/laravel-permission: scan, shadow mode, decision diffing, cutover |
Documentation
Full documentation is published at doc.laravel-iam-client.padosoft.com —
quickstart, guides (iam.can, the Gate adapter, the facade, transports, ReBAC, step-up, caching), the
fail-closed theory, architecture + ADRs, and a complete PHP/config reference. The source for that site lives
in docs/.
Security
This client is fail-closed by design: any transport error, unreachable PDP, non-2xx response or engine exception resolves to deny — never an allow, never an opaque 500. Step-up-required permits are treated as not-yet-granted. There is no fail-open switch. If you discover a security issue, please email [email protected] rather than opening a public issue.
License
MIT © Padosoft. See LICENSE.
All versions of laravel-iam-client with dependencies
padosoft/laravel-iam-contracts Version ^1.3
spatie/laravel-package-tools Version ^1.16
lcobucci/jwt Version ^5.0
guzzlehttp/guzzle Version ^7.0