vizir/laravel-keycloak-web-guard
Laravel authentication guard that signs users in to your web app through Keycloak. It handles login, logout, token refresh, and role-based route protection, delegating identity to Keycloak via OpenID Connect with minimal configuration and no custom auth code to maintain.
Architecture fit. The package targets a narrow but legitimate slot: server-rendered Laravel applications (Blade/Livewire/Inertia-with-session) that delegate authentication to Keycloak via the OIDC Authorization Code flow. It plugs into Laravel's native Auth extension points — a custom guard plus a user provider configured in config/auth.php — so it does not fight the framework. It is a poor fit for stateless API backends, mobile clients, or SPA-first architectures; those need a token-validation guard (the sibling API-oriented package) or a BFF pattern. Confirm the intended topology before treating this as a candidate at all.
Integration feasibility. Mechanically low-effort: Composer install, publish config, set realm/client/base-URL/redirect-URI environment variables, register the guard and provider, attach middleware to the web route group. The integration surface is small, which caps the blast radius of adoption. The real feasibility gate is not code volume but version currency — the repository is archived, the score (~4.95/10) reflects that, and Composer constraints almost certainly predate the Laravel 10/11 and PHP 8.2+ era. Treat "does it install against our target framework version" as a go/no-go spike, not an assumption.
Technical risk. The dominant risk is lifecycle, not engineering: an archived package receives no CVE response, no OIDC spec corrections, and no dependency bumps, while its transitive tree (HTTP client, JWT/JOSE libraries, framework constraints) continues to drift. Secondary risks are protocol-level: ID-token signature and nonce/state validation, PKCE support, refresh-token rotation, RP-initiated logout, and how tokens are persisted in the session (server-side session storage is acceptable; cookie storage is not). Third is Keycloak coupling — behavior changes across Keycloak's WildFly→Quarkus transition and recent realm/client defaults may not be accounted for.
Key questions.
state, nonce, and ID-token signature?Stack fit. Best fit: Laravel monolith, session driver backed by Redis or database, Keycloak as the sole IdP, roles expressed as Keycloak realm/client roles. Acceptable fit: Inertia or Livewire apps where the session cookie is the auth carrier. Poor fit: anything requiring per-request bearer-token validation, multi-IdP federation, or offline/CLI access.
Migration path. From a bespoke OIDC/SAML integration or Socialite, this is a guard swap behind the same route middleware — comparatively clean. From local Laravel auth, plan a transitional period with both guards active and account linking on a stable claim (sub preferred, email as fallback with a reconciliation job), then retire the local guard. Do not attempt a hard cutover; the user-identity mapping is where migrations fail.
Compatibility. Pin the Composer constraint to the exact Laravel minor we run, and verify the full dependency tree resolves. Given archived status, the realistic options are: (a) consume as-is with a pinned lockfile and an internal risk acceptance, (b) fork into our VCS namespace, apply framework/PHP compatibility patches and dependency bumps, and reference via a VCS repository entry, or (c) use it as a reference implementation and reimplement the guard in-house (~a few hundred lines). Option (b) is the default recommendation; (c) is worth costing if the package's protocol handling is thin.
Sequencing.
Maintenance. Assume full ownership of the code path from day one. Budget recurring effort for dependency and security patching, Keycloak upgrade compatibility testing, and OIDC protocol review — realistically a few days per quarter, plus a spike each time Keycloak or Laravel ships a major. The archived status converts a "free" dependency into a small internal product.
Support. No upstream maintainer, no SLA, no guaranteed responses on issues. Support is internal: a runbook covering redirect-URI misconfiguration, realm/client secret rotation, session invalidation, and Keycloak outage behavior. Ensure at least two engineers can operate it.
Scaling. The guard itself is cheap per request; scaling pressure lands elsewhere. Session storage becomes the constraint (size and TTL of token-bearing sessions), and login/refresh bursts concentrate load on Keycloak — so Keycloak needs its own HA posture and the app needs refresh jitter to avoid thundering herds at token expiry. If the package performs userinfo or introspection calls per request, model that as a synchronous dependency on the IdP's availability and latency budget.
Failure modes.
HttpOnly/Secure/SameSite.Ramp-up. One to two days for a Laravel developer to wire and configure; one to two weeks before the team is genuinely confident in OIDC edge cases (refresh, logout, claim mapping). Require at least one engineer with real OIDC/Keycloak depth — the package hides the happy path well but not the failure modes. Verdict: viable as a short-term accelerator for a session-based Laravel app already standardized on Keycloak, contingent on forking and owning it; not viable as a long-term unmodified dependency.
How can I help you explore Laravel packages today?