PHP code example of febrianrz / laravel-keycloak-guard
1. Go to this page and download the library: Download febrianrz/laravel-keycloak-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/ */
febrianrz / laravel-keycloak-guard example snippets
// keycloak.php
'input_key' => 'api_token'
// If there is no Bearer token on request it will use `api_token` request param
GET $this->get("/foo/secret?api_token=xxxxx")
POST $this->post("/foo/secret", ["api_token" => "xxxxx"])
...
'defaults' => [
'guard' => 'api', # <-- For sure, i`m building an API
'passwords' => 'users',
],
....
'guards' => [
# <!-----
# Make sure your "api" guard looks like this.
# Newer Laravel versions just removed this config block.
# ---->
'api' => [
'driver' => 'keycloak',
'provider' => 'users',
],
],
// public endpoints
Route::get('/hello', function () {
return ':)';
});
// protected endpoints
Route::group(['middleware' => 'auth:api'], function () {
Route::get('/protected-endpoint', 'SecretController@index');
// more endpoints ...
});
// public endpoints
$router->get('/hello', function () {
return ':)';
});
// protected endpoints
$router->group(['middleware' => 'auth'], function () {
$router->get('/protected-endpoint', 'SecretController@index');
// more endpoints ...
});
$token = Auth::token() // or Auth::user()->token()