- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Authorization
The package integrates with Laravel's Gate, enabling Blade directives to check roles and permissions.
@can('posts.create')
    <!-- user can create posts -->
@endcan
@cannot('permission:posts.delete')
    <!-- no delete rights -->
@endcannot
@canany(['role:admin', 'permission:posts.update'])
    <!-- admin or user with update permission -->
@endcananyUse hasRole and hasPermissionTo methods on the authenticated user for programmatic checks:
if (auth()->user()->hasRole('admin')) {
    // ...
}Authentication is handled via JWT tokens validated by the JWT Authentication middleware or by the session-based Gateway Guard.
Refer to the linked pages for configuration details.
When integrating with an OpenID Connect provider—such as Keycloak—enable JWKS support and claim mapping so the middleware can decode tokens and expose roles/permissions consistently:
- Set OIDC_ENABLED=trueand pointOIDC_JWKS_URLto the provider's JWKS endpoint (e.g.https://id.example.com/realms/<realm>/protocol/openid-connect/certs). The validator automatically honours key rotation.
- Align the user identifier with JWT_USER_IDENTIFIER_CLAIM. Usingsubis recommended so permission lookups and audit logs reference the provider's subject.
- Populate the claims consumed by the middleware:
- Primary roles are read from realm_access.rolesby default.
- Client roles are collected from resource_access.{client}.roleswhenOIDC_CLIENT_IDis provided; otherwise all client roles are flattened. Override viaOIDC_CLIENT_ROLES_CLAIMorJWT_PERMISSIONS_CLAIMif your IdP uses custom mappers.
 
- Primary roles are read from 
- Leave OIDC_PREFER_GATEWAY_PERMISSIONS=falseto trust the token contents; set it totruewhen the API gateway remains the single source of truth and should always be queried byLoadAccess.
- Add custom protocol mappers in your IdP if you need explicit rolesorpermissionsarrays in the token—JWT_ROLES_CLAIMandJWT_PERMISSIONS_CLAIMcan then point to those flat claims.
After configuration, auth()->user()->hasRole() and hasPermissionTo() will reflect the role sets embedded in the OIDC token without extra network hops.
Maintained by @KroderDev
💬 Feedback? Open an issue
Last updated: July 1, 2025