Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Guarded Authentication Bundle Laravel Package

jafar/guarded-authentication-bundle

A PHP authentication bundle that adds guarded authentication to your application, with configurable guards, access checks, and a straightforward setup for integrating secure login flows into existing projects. Designed to keep authentication logic organized and easy to extend.

View on GitHub
Deep Wiki
Context7

Getting Started

First, a framing note: despite the "bundle" naming and the fact you're asking as a Laravel developer, this is a Symfony bundle — it hooks into security.yaml, the Symfony authenticator system, and the DI container. There is no Laravel service provider here. If you're on Laravel, nothing in this package transfers directly; the equivalent stack is tymon/jwt-auth (or Sanctum) plus a custom guard. If you're on Symfony, read on.

Minimal path to first login:

  1. Check composer.json before anything else. v4.0.0 states Symfony 6 support and PHP 8+, so expect something like symfony/*: ^5.4|^6.0 and php: ^8.0 (Symfony 6.0 itself requires PHP 8.0.2+, so verify the exact floor). Note the notes say nothing about Symfony 7 — assume 6.x is the ceiling until proven otherwise.
  2. composer require jafar/guarded-authentication-bundle:^4.0, then register it in config/bundles.php.
  3. Add the bundle's config file under config/packages/. Don't guess the root key — open DependencyInjection/Configuration.php, which is the authoritative tree of every option the bundle accepts.
  4. Wire the bundle's authenticator(s) into a firewall in config/security.yaml using the Symfony 5.3+/6 style — custom_authenticators: under the firewall — not the old guard: key.
  5. Ensure your User entity implements UserInterface and PasswordAuthenticatedUserInterface, and that a user provider is configured.

Where to look first, in order: the README (expect it to be thin), then DependencyInjection/Configuration.php (what you can configure), then the Security/ directory (what actually authenticates), then Resources/config/services.yaml (service IDs you can override or decorate). If there's a Tests/ directory, that's your best usage documentation.

Verify the v4 claim immediately. "Works with Symfony 6" is a one-line release note. Symfony 6 removed the Guard component outright, so if Security/ still contains classes extending AbstractGuardAuthenticator, this release is mislabelled and you should stop there. Run grep -rn "Guard" src/ and composer why-not symfony/framework-bundle 6.0 before writing any config.

Your first real use case is the one this bundle was built for: a JSON login endpoint (POST /api/login_check style) that validates credentials and returns a signed token, plus a stateless API firewall that authenticates subsequent requests from an Authorization header. Get that working end-to-end on a scratch app before touching a production firewall.

Implementation Patterns

Two firewalls, two authenticators. This is the pattern the bundle is designed around: a main firewall with form_login (session, cookies, CSRF) for the browser, and a separate api firewall with stateless: true for token auth. Do not try to run both authenticators on one firewall — the login authenticator's supports() should match only the login path, and the token authenticator should match only requests carrying the header.

Login authenticator vs. token authenticator. Expect the bundle to ship both. The first reads POSTed credentials, calls the user provider, verifies the password hash, and returns a response containing the JWS. The second is header-driven and runs on every API request. Keep them on separate firewalls and keep the login route outside the protected path prefix, or you'll get redirect loops. In v4 these should be registered via custom_authenticators, and the login one will typically be an entry point too.

Override, don't fork. The bundle's services are the extension point. To change the token payload (add roles, tenant ID, custom claims) or the response shape, decorate the relevant service in services.yaml (decorates: <bundle.service.id>) rather than editing vendor code. Use bin/console debug:container --tag=security.authenticator and debug:container <service.id> to discover exactly what's registered.

Integration with the rest of your app. Once authenticated, the token subject resolves to your User through the provider, so normal $this->getUser(), isGranted(), and voters work unchanged. Symfony's security.access_control rules apply to the API firewall too — put ^/api rules there rather than hand-rolling checks in controllers.

Testing. Use KernelBrowser (or ApiTestCase if you're on API Platform): post credentials to the login route, assert a token in the body, then set HTTP_AUTHORIZATION on subsequent requests. Write one test that asserts an expired/malformed token yields 401 — that's the path most likely to regress and the one no one tests. On v4, add a test that boots the kernel on Symfony 6.4 (the last 6.x LTS) so a future PHP/Symfony bump doesn't silently break DI wiring.

Key management. Whatever option holds the signing key/secret, source it from an environment variable or Symfony Secrets Vault. Never commit it, and never share it between environments.

Gotchas and Tips

  • The Symfony 6 ceiling is now the headline risk. v4.0.0 buys you Symfony 6, but Symfony 6.4 is the last 6.x LTS and 7.x is already current. There is no stated 7 support, and the jump to 7 removes more deprecated APIs. Treat this release as a reprieve, not a fix, and keep the migration plan live: Symfony's native json_login authenticator covers the login half, and lexik/jwt-authentication-bundle covers the token half. Your exit path remains replace, not upgrade.
  • Confirm the Guard removal before trusting the changelog. One sentence of release notes is not a migration guide. There are no upgrade notes here about BC breaks in the authenticator API, changed service IDs, renamed config keys, or a new token format. Diff DependencyInjection/Configuration.php against the 3.x tree — if config keys moved, a silent misconfiguration is easy. Also re-pin your composer.json and clear the container cache (bin/console cache:clear) after upgrading; stale compiled containers are the usual cause of "the new version still behaves like the old one."
  • Still 8 stars, 0 dependents, single maintainer. A major version bump does not create an ecosystem, third-party write-ups, or an advisory feed. Treat the auth code as code you now own. Budget a read-through of Security/ before production, and vendor-pin the exact version — ^4.0 will pick up whatever 4.0.x ships next.
  • "JWS" is not "JWT" in the full sense. Signed, not encrypted — the payload is base64url-readable by anyone holding the token. Don't put anything sensitive in claims. Also check which algorithm is used: an HS256 shared secret is symmetric (any verifier can mint tokens); RS256 is asymmetric and preferable if you have multiple consumers. If v4 changed the default algorithm, that's a security-relevant change worth catching in review.
  • No refresh/revocation story. Stateless tokens can't be logged out server-side. Design around short TTLs, and if you need revocation, you're adding a denylist — which is a project, not a config flag.
  • Debugging tools that actually help: bin/console debug:firewall <name> to see authenticators and the entry point, bin/console debug:config security to confirm your YAML actually merged, the profiler's Security panel for token/roles at request time, and monolog at debug on the security channel to trace why an authenticator returned false from supports().
  • CORS preflight will hit your firewall. OPTIONS requests carry no Authorization header. Make sure your CORS listener runs at high priority so preflight short-circuits before the authenticator 401s.
  • stateless: true means no session. If you see session cookies being set on your API firewall, the config isn't taking — check for security.firewalls.api.stateless and any listener accidentally touching the session. Also confirm security.enable_authenticator_manager is not lingering in your config; that toggle was for the 5.x transition and is gone in 6.
  • PHP 8 floor means fewer deprecation floods, not none. The 2022-era ReturnTypeWillChange noise should be gone on 8.1+, but you may still see deprecations from Symfony internals the bundle calls. Don't silence them globally; fix locally or upgrade.
  • Bottom line for day-to-day use: v4.0.0 legitimately reopens this for brownfield Symfony 6 apps already shaped around it, and that's a real improvement over the previous assessment. For greenfield — or for anything heading to Symfony 7 — use the native authenticator system plus a maintained JWT bundle. You'll spend less time on auth than you will reading this bundle's source.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource