alma-medical/keycloak-client
Composer 安装命令:
composer require alma-medical/keycloak-client
包简介
A PHP client for Keycloak REST API
关键字:
README 文档
README
This package provides a PHP wrapper for Keycloak REST API.
Installation
Run this command to integrate the Keycloak REST API client to your existing project:
composer require alma-medical/keycloak-client
How to use it
First of all we need to configure a oauth2 provider for authenticating against Keycloak. For that purpose we use the stevenmaguire/oauth2-keycloak package, a league/oauth2-client Keycloak provider. This is an example of how to do that:
use Stevenmaguire\OAuth2\Client\Provider\Keycloak as KeycloakProvider; $provider = new KeycloakProvider([ 'authServerUrl' => 'https://my-keycloak.com/auth', 'clientId' => 'myClientId', 'clientSecret' => 'myCleintSecret', 'realm' => 'myRealm', ]);
Once we have our provider instance we need to create an API client:
use AlmaMedical\KeycloakClient\Keycloak; $client = new Keycloak($provider);
Now we can call any api method with callMedthod() function:
$response = $client->callMethod('users');
To make easier the parse of the responses, some methods have been implemented:
Get users
This method gets all the users:
use AlmaMedical\KeycloakClient\Method\GetUsers; $getUsers = new GetUsers($client); $users = $getUsers->call();
Get user
This method get a user
use AlmaMedical\KeycloakClient\Method\GetUser; $getUsers = new GetUser($client, 'user_id'); $user = $getUsers->call();
Cache
You can use a Psr\Cache\CacheItemPoolInterface to cache Keycloak tokens. To use it simply set your CacheItemPoolInterface and the client will package will use it:
use Symfony\Component\Cache\Adapter\FilesystemAdapter; $client->setCachePool(new FilesystemAdapter());
Running tests
To run the tests run the following command:
./vendor/bin/phpunit
统计信息
- 总下载量: 5.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-12-05