Laravel Single Sign On (SSO) authenticatable credentials implementation.
firmantr3/laravel-sso is a Laravel package for laravel single sign on (sso) authenticatable credentials implementation..
It currently has 2 GitHub stars and 55 downloads on Packagist (latest version 2.0.3).
Install it with composer require firmantr3/laravel-sso.
Discover more Laravel packages by firmantr3
or browse all Laravel packages to compare alternatives.
Last updated
Create just one unique credential for multiple authenticatable users that has different eloquent model.
Given you need to implement a school management application, that have 3 different user: admins, teachers, students. Sometimes, admins can be teacher as well, how if the email and password don't need to be different? Well, Laravel SSO to the rescue!
composer require firmantr3/laravel-sso
Publish migration by running artisan vendor:publish:
php artisan vendor:publish
Update your laravel auth config: /config/auth.php, and use sso provider, like so:
'providers' => [
'admins' => [
'driver' => 'sso',
'model' => App\Admin::class,
],
'teachers' => [
'driver' => 'sso',
'model' => App\Teacher::class,
],
'students' => [
'driver' => 'sso',
'model' => App\Student::class,
],
],
You can use preset Credential model: Firmantr3\LaravelSSO\Models\Credential. You can also create your own Credential model class that extends from Firmantr3\LaravelSSO\Models\Credential so you can customize the child relations, and then update your class namespace in config/sso.php.
Your user models must have credential_id AND Laravel's default user attributes like remember_token, check your user model migration. The credential_id should be unique for each models, to prevent duplication.
User model's class must extend Firmantr3\LaravelSSO\Models\User like so:
<?php
namespace App\Admin;
use Firmantr3\LaravelSSO\Models\User;
class Admin extends User
{
public $timestamps = false;
protected $table = 'admins';
}
You can attach existing users using attachUser method on a Credential model like so:
$credential = Firmantr3\LaravelSSO\Models\Credential::first();
$admin = $credential->attachUser(\App\Admin::create());
Or you can use createAuthenticatableUser method on a Credential:
$adminClass = \App\Admin::class;
$adminAttributes = [];
$admin = $credential->createAuthenticatableUser($adminClass, $adminAttributes);
vendor/bin/phpunit