PHP code example of 1-0-0-1 / laravel-keycloak-extended-guard
1. Go to this page and download the library: Download 1-0-0-1/laravel-keycloak-extended-guard 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/ */
1-0-0-1 / laravel-keycloak-extended-guard example snippets
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'keycloak' => [ # <-- Add this block
'driver' => 'keycloak',
'provider' => 'users',
],
// public endpoints
Route::get('/hello', function () {
return ':)';
});
// protected endpoints
Route::middleware('auth:keycloak')->post('/secret_page', function () {
return 'Welcome to secret place';
});
return [
// Keycloak secret (Configure->Realm Settings->Keys->RS256->Public key)
'client_secret' => env('KEYCLOAK_CLIENT_SECRET', ''),
// Confirm token with request to keycloak server
'> env('KEYCLOAK_LOAD_USER', false),
'user_provider_credential' => env('KEYCLOAK_USER_PROVIDER_CREDENTIAL', 'username'),
'token_principal_attribute' => env('KEYCLOAK_TOKEN_PRINCIPAL_ATTRIBUTE', 'preferred_username'),
];
php artisan vendor:publish --provider="KeycloakExtendedGuard\KeycloakExtendedGuardServiceProvider"