smskin/laravel-identity-service-client is a Laravel package for guards for auth by identity service.
It currently has 0 GitHub stars and 32 downloads on Packagist.
Install it with composer require smskin/laravel-identity-service-client.
Discover more Laravel packages by smskin
or browse all Laravel packages to compare alternatives.
Last updated
Identity service is a service that allows you to organize authorization in a laravel application through a common remote server. This allows you to organize a multi-service architecture with end-to-end authorization.
Identity service library consists of 2 parts:
composer require smskin/laravel-identity-service-clientphp artisan vendor:publish --tag=identity-service-clientidentity-service-client.php in config folder and environmentsphp artisan migrateUser will be creating automatically if user open site with correct jwt. You must change users table for support nullable fields.
I usually remove all columns except id and dates because they are not needed (authorization happens through a remote server). For example:
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
You can configure library with identity-service-client.php file.
HasIdentity contract and implement IdentityTrait traitScope::IDENTITY_SERVICE_LOGIN scopeExample of Users model:
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use SMSkin\IdentityServiceClient\Models\Contracts\HasIdentity;
use SMSkin\IdentityServiceClient\Models\Traits\IdentityTrait;
class User extends Authenticatable implements HasIdentity
{
use HasApiTokens, HasFactory, Notifiable;
use IdentityTrait;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'identity_uuid',
'name',
];
}
This library register 2 guards:
You can use it with auth middleware (for example: auth:identity-service-client-jwt) or bind it's to already exists guards by auth.php config file.
For example:
...
'guards' => [
'web' => [
'driver' => 'identity-service-client-session',
'provider' => 'users',
],
'api' => [
'driver' => 'identity-service-client-jwt',
'provider' => 'users',
],
],
...
User has method hasScope for check required scope in jwt.
Gate::define('viewNova', function (User $user) {
return $user->hasScope(Scopes::IDENTITY_SERVICE_LOGIN);
});
identity-service-client.scopes.initial)/identity-service/api/identity/scopes method for receive available user scopesidentity-service-client.scopes.uses)/identity-service/api/auth/jwt/refresh method for refresh the token with uses scopes