PHP code example of taufik-t / uauth-oidc-client
1. Go to this page and download the library: Download taufik-t/uauth-oidc-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
taufik-t / uauth-oidc-client example snippets
'uauth' => [
'base_url' => env('UAUTH_BASE_URL'),
'client_id' => env('UAUTH_CLIENT_ID'),
'client_secret' => env('UAUTH_CLIENT_SECRET'),
'redirect' => env('UAUTH_REDIRECT_URI'),
],
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
$event->extendSocialite('uauth', \SocialiteProviders\UAuth\Provider::class);
});
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
// ... other providers
\SocialiteProviders\UAuth\UAuthExtendSocialite::class.'@handle',
],
];
return Socialite::driver('uauth')->redirect();
$user = Socialite::driver('uauth')->user();
$locale = $user->user['locale'];
$email_verified = $user->user['email_verified'];
'uauth' => [
'base_url' => env('UAUTH_BASE_URL'),
'client_id' => env('UAUTH_CLIENT_ID'),
'client_secret' => env('UAUTH_CLIENT_SECRET'),
'redirect' => env('UAUTH_REDIRECT_URI'),
'scopes' => 'roles groups',
// or
'scopes' => env('UAUTH_SCOPES'),
],
'routes' => [
'enabled' => env('UAUTH_ROUTES_ENABLED', true),
],
'providers' => [
/*
* Package Service Providers...
*/
// ...
SocialiteProviders\UAuth\UAuthServiceProvider::class,
],
Route::group(['middleware' => ['sso.auth']], function () {
// authenticated users only
});
Route::group(['middleware' => ['sso.guest']], function () {
// unauthenticated users only
});
Route::group(['middleware' => ['sso.auth', 'sso.role:user']], function () {
// authenticated users with specified role only
});
Route::group(['middleware' => ['sso.auth', 'sso.role:user|admin|manager']], function () {
// authenticated users with multiple roles
});
public function __construct()
{
$this->middleware('sso.auth');
$this->middleware('sso.guest');
$this->middleware('sso.role:user');
$this->middleware('sso.role:user')->only(['index']);
$this->middleware('sso.role:admin|manager')->only(['index','create']);
$this->middleware('sso.role:manager')->except('destroy');
}
@ssoRole('admin')
<a href="{{ url('/admin') }}">Admin</a>
@endSsoRole
//
@ssoRole('user|admin')
<a href="{{ url('/home') }}">Home</a>
@endSsoRole
//
@ssoRole(['user','admin'])
<a href="{{ url('/home') }}">Home</a>
@endSsoRole
<a href="{{ route('uauth.logout') }}">Logout</a>
// redirect setelah logout ke url tertentu
<a href="{{ route('uauth.logout', ['redirect_uri' => 'https://your-redirect-url.com']) }}">Logout</a>
bash
php artisan vendor:publish --provider="SocialiteProviders\UAuth\UAuthServiceProvider"
# or
php artisan vendor:publish --tag=uauth