alma-medical/keycloak-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固