A helper package for Forisa SSO authentication in laravel framework
- PHP 7.2.5 or greater
- Laravel version 6
- Guzzle 7.5 or greater
Install using composer:
place this code in composer.json
"require": {
"forisa/sso" : "dev-master"
},
"repositories": [
{
"url": "https://github.com/bagus-repository/laravel-sso",
"type": "git"
}
]
Use provided button
use Forisa\Sso\Facade\Sso;
then in blade
{!! Sso::SsoLoginButton() !!}
or use your own button with link
route('sso.redirect')
@method static void logout()
-
Call static logout method (run this method after all client session destroyed)
use Forisa\Sso\Facade\Sso; Sso::logout($request);
@method static bool check()
use Forisa\Sso\Facade\Sso;
Sso::check();
or
@method static bool checkBySession()
use Forisa\Sso\Facade\Sso;
Sso::checkBySession();
@method static \Forisa\Sso\Models\User|null user()
use Forisa\Sso\Facade\Sso;
Sso::user();
@method static void setUser(\Forisa\Sso\Models\User $user)
use Forisa\Sso\Facade\Sso;
use Forisa\Sso\Models\User;
$user = Sso::user();
Sso::set($user);
use Forisa\Sso\Facade\Sso;
Sso::token();
Call middleware sso
from route or controller to check if user is authenticated or not
Route::middleware(['web', 'sso'])
sso()->
same as Sso::
, it can be called from controller, route, view, etc.
sso()->check()
sso()->user()
...
return [
'check_token_type' => env('FORISASSO_CHECK_TOKEN_TYPE', 'session'),
'app_code' => env('FORISASSO_APP_CODE'),
'base_url' => env('FORISASSO_BASE_URL'),
'base_ip' => env('FORISASSO_BASE_IP'),
'api_url' => env('FORISASSO_API_URL'),
'api_ip' => env('FORISASSO_API_IP'),
'post_login_redirect_uri' => env('FORISASSO_POST_LOGIN_REDIRECT_URI'),
'post_logout_redirect_uri' => env('FORISASSO_POST_LOGOUT_REDIRECT_URI'),
'scope' => env('FORISASSO_SCOPE'),
'allowed_roles' => [
'Role1',
'Role2',
'Role3'
],
];
also client must be registered in auth server and provide valid host
Example: career.forisa.co.id / 192.168.50.111