impact-factoring / accounts-user-provider
A Laravel User provider for Impact Factoring Accounts
Installs: 271
Dependents: 0
Suggesters: 0
Security: 0
pkg:composer/impact-factoring/accounts-user-provider
Requires
- illuminate/cookie: ^11.0 || ^12.0
- illuminate/support: ^11.0 || ^12.0
- impact-factoring/accounts-client: ^1.0
- spatie/laravel-permission: ^6.7
Requires (Dev)
- orchestra/testbench: ^10.6
- phpunit/phpunit: ^12
README
This package provides a Laravel user provider that integrates with Impact Factoring Accounts, allowing you to authenticate and manage users directly from the Accounts Server.
Quick Start
- composer require impact-factoring/accounts-user-provider
- php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
- php artisan migrate
- Update auth.php and User.php (see below)
- Add IMPACT_FACTORING_ACCOUNTS_BASE_URL to .env
Requirements:
- Laravel 11+
- php 8.2+
Installation:
Install the package using Composer:
composer require impact-factoring/accounts-user-provider
After package installation, run the following commands:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
Configuration
Once migration is done, update the following files:
auth.php:
Change the user provider driver from 'eloquent' to 'impact-factoring-accounts-user-provider':
'providers' => [
    'users' => [
        'driver' => 'impact-factoring-accounts-user-provider',
        'model' => App\Models\User::class,
    ],
],
User.php:
Extend your local User model with the User model from the package:
use ImpactFactoring\Accounts\Models\User as Authenticatable;
Remove $hidden property from your local User model, to ensure all user attributes from Accounts are accessible.
.env:
Add the following environment variable:
IMPACT_FACTORING_ACCOUNTS_BASE_URL=<your_base_url_here>
Set this variable to where your local Accounts server is hosted. For example: http://localhost:8081.
Authentication routes
This package contains two authentication routes:
- POST '/login' -> Process login request
- POST '/logout' -> Process logout request (route name: 'logout')
You are free to use whatever frontend you desire, but processing needs to be done by these two routes.
So, make sure you don't have any routes that may be in conflict with these two.
Middleware
This package registers a middleware with the alias `accounts.auth`
This middleware ensures the user is authenticated via Accounts.
You can use this middleware on your own routes.
Example:
Route::get('/', [HomeController::class, 'index'])->middleware('accounts.auth')
Scheduled Command
The package automatically registers a command that will synchronize roles and permissions from Accounts. This command will run every hour. You can also manually start this command:
php artisan accounts:sync-roles-and-permissions
Development
This package contains a Docker Compose file. Use the following Composer scripts to run and debug in an isolated environment
Usage
Initial composer install
composer docker-install
To test the package (powered by: Orchestra Testbench)
composer test
Run a debug container
composer debug