PHPackages                             klsoft/php-keycloak-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. klsoft/php-keycloak-client

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

klsoft/php-keycloak-client
==========================

A PHP library that can be used to secure web applications with Keycloak.

1.0.0(3mo ago)06MITPHPPHP &gt;=8.1

Since Feb 6Pushed 3mo agoCompare

[ Source](https://github.com/klsoft-web/php-keycloak-client)[ Packagist](https://packagist.org/packages/klsoft/php-keycloak-client)[ Docs](https://github.com/klsoft-web/php-keycloak-client)[ RSS](/packages/klsoft-php-keycloak-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP-KEYCLOAK-CLIENT
===================

[](#php-keycloak-client)

A PHP library that can be used to secure web applications with Keycloak. It is typically used in conjunction with RESTful web service APIs.

See also:

- [YII2-JWT-AUTH](https://github.com/klsoft-web/yii2-jwt-auth) - The package provides a [Yii 2](https://www.yiiframework.com) authentication method based on a JWT token
- [YII2-KEYCLOAK-AUTHZ](https://github.com/klsoft-web/yii2-keycloak-authz) - The package provides Keycloak authorization for the web service APIs of [Yii 2](https://www.yiiframework.com)
- [YII3-JWT-AUTH](https://github.com/klsoft-web/yii3-jwt-auth) - The package provides a [Yii 3](https://yii3.yiiframework.com) authentication method based on a JWT token
- [YII3-KEYCLOAK-AUTHZ](https://github.com/klsoft-web/yii3-keycloak-authz) - The package provides Keycloak authorization for the web service APIs of [Yii 3](https://yii3.yiiframework.com)

Requirement
-----------

[](#requirement)

- PHP 8.1 or higher.

Installation
------------

[](#installation)

```
composer require klsoft/php-keycloak-client
```

Example of initializing a KeycloakClient
----------------------------------------

[](#example-of-initializing-a-keycloakclient)

```
use Klsoft\KeycloakClient\KeycloakClient;

$keycloakClient = new KeycloakClient(
    "http://localhost:8080/realms/myrealm", //Keycloak realm URL
    "Keycloak client ID",
    "http://localhost/login", //Keycloak client redirect URI
    "Keycloak client secret"); //This is optional, but it is required when Keycloak 'Client authentication' is ON
```

Example of creating an Authorization Code flow URL
--------------------------------------------------

[](#example-of-creating-an-authorization-code-flow-url)

```
