ingenius / auth
Authentication package for Ingenius
1.0.0
2025-07-24 17:05 UTC
Requires
- php: ^8.1
- ingenius/core: *
- laravel/framework: ^12.0
- spatie/laravel-permission: ^6.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^11.0
README
This package provides authentication functionality for the Ingenius platform, including:
- User authentication for tenants
- Role and permission management
- Middleware for tenant authentication and permission checks
- Helper functions for authentication
Installation
composer require ingenius/auth
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=ingenius-auth-config
Migrations
Publish the migrations:
php artisan vendor:publish --tag=ingenius-auth-migrations
Run the migrations:
php artisan migrate
Usage
Authentication
use Ingenius\Auth\Helpers\AuthHelper; // Get authenticated user from any guard $user = AuthHelper::getUser(); // Check if user is authenticated in any guard if (AuthHelper::check()) { // User is authenticated } // Get user from a specific guard $tenantUser = AuthHelper::getUserFromGuard('tenant'); $sanctumUser = AuthHelper::getUserFromGuard('sanctum');
Middleware
The package provides two middleware:
tenant.user
: Ensures the user is authenticated in the tenant contexttenant.permission
: Checks if the user has the required permission
// In your routes file Route::middleware(['tenant.user'])->group(function () { Route::get('/dashboard', 'DashboardController@index'); }); Route::middleware(['tenant.user', 'tenant.permission:auth.users.view'])->group(function () { Route::get('/users', 'UserController@index'); });
Commands
The package provides the following commands:
ingenius:auth:sync-tenant-permissions
: Synchronizes permissions from the PermissionsManager to tenant databasesingenius:auth:add-admin-role-to-user
: Adds an admin role to an existing user in a tenant and assigns all permissions to that role
# Sync permissions for all tenants php artisan ingenius:auth:sync-tenant-permissions # Sync permissions for a specific tenant php artisan ingenius:auth:sync-tenant-permissions --tenant=1 # Add admin role to a user php artisan ingenius:auth:add-admin-role-to-user 1 user@example.com
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.