spiral/security
Spiral Security adds authentication and authorization tooling for Spiral apps, including guards, token and session support, and role/permission checks. Keep access control consistent across HTTP and console with a clean, framework-native API.
Start by installing the package via Composer into a Spiral application (composer require spiral/security). Once installed, register the security module in your app/src/Kernel.php by adding Spiral\Security\SecurityModule to the list of bootloaders. The core entry point is the SecurityInterface, which you’ll inject into controllers or services to perform checks like can($user, $ability, $arguments). The first practical use case is setting up an IdentityInterface implementation (e.g., User entity) and an AuthenticationInterface to resolve the current user—typically via middleware that hydrates a user from a token or session.
PolicyInterface (e.g., PostPolicy), then register them with PolicyInterface::class => PostPolicy::class in your service provider. Use $security->can($user, 'update', $post) in controllers or domain services.$security->denyUnlessCan($user, 'delete', $resource)) to throw AccessDeniedException automatically on failure.IdentityInterface for different auth models (e.g., API tokens, OIDC). Integrate with your ORM (e.g., Spiral Database, ORM) in the identity loader—avoiding direct DB access in controllers.SecurityInterface in unit tests to assert access control logic without touching auth providers. Use $this->mock(SecurityInterface::class)->set('can', true) in feature tests.Spiral\Security\Middleware\AuthMiddleware) to auto-resolve and attach the current identity to the request context—enabling $security->getUser() to work everywhere.can(null, ...) can throw or return false depending on policy design—implement null-safe guards in policies.default policy class (via PolicyInterface::class) to catch undefined abilities gracefully instead of crashing.['teamId' => $team->id]) to can() to enable nuanced checks (e.g., “can edit post only in their team”).SecurityInterface implementation by binding your own class in a bootloader— useful for adding logging, audit trails, or custom exception handling.How can I help you explore Laravel packages today?