PHPackages                             yangze/oauth2-keycloak - 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. yangze/oauth2-keycloak

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

yangze/oauth2-keycloak
======================

A wrapper for the Keycloak OAuth 2.0 Client Provider

v2.0.9(4y ago)03.5k1MITPHPPHP ^7.3|^8.0

Since Jan 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/zhenyangze/oauth2-keycloak)[ Packagist](https://packagist.org/packages/yangze/oauth2-keycloak)[ RSS](/packages/yangze-oauth2-keycloak/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (44)Used By (0)

oauth2-keycloak
===============

[](#oauth2-keycloak)

A wrapper for the Keycloak OAuth 2.0 Client Provider, support Authentication and Authorization.

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

[](#installation)

To install, use composer:

```
composer require yangze/oauth2-keycloak
```

Init
----

[](#init)

```
$passport = Passport::init([
    'authServerUrl' => 'http://127.0.0.1:8080/auth',
    'realm'         => 'xxxx',
    'clientId'      => 'backend',
    'clientSecret'  => 'xxxxx',
    'redirectUri'   => 'http://127.0.0.1:8003/auto',
    'periodNoCheck' => 3600,
    'periodCheck'   => 180,
]);
```

Authentication
--------------

[](#authentication)

### Login

[](#login)

```
$user = $passport->checkLogin();
$user->getAttr('username');
$user->toArray();
```

### logout

[](#logout)

```
$passport->logout();
```

### Other Methds

[](#other-methds)

```
$passport->getAccessToken(); // can save in client
$passport->getToken(); // secret
$passport->getAuthorizationUrl();
$passport->getLogoutUrl();
```

Authorization
-------------

[](#authorization)

```
$user = $passport->checkAuth();

// permission
$user->can($resource, $scope);
$user->cannot($resource, $scope);

// list
$user->getClients();
$user->getPermissions();

// role
$user->getRoles();
$user->hasRole($role);
$user->inRoles($roleList);
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Recently: every ~1 days

Total

35

Last Release

1781d ago

Major Versions

v1.0.17 → v2.0.32021-05-27

v1.0.19 → v2.0.62021-06-21

v1.0.20 → v2.0.72021-08-05

v1.0.22 → v2.0.82021-08-16

v1.0.23 → v2.0.92021-08-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/731316?v=4)[yangze](/maintainers/yangze)[@yangze](https://github.com/yangze)

---

Top Contributors

[![zhenyangze](https://avatars.githubusercontent.com/u/15710584?v=4)](https://github.com/zhenyangze "zhenyangze (27 commits)")

---

Tags

authenticationauthorizationkeycloakoauthclientoauthoauth2authorizationauthorisationkeycloak

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/yangze-oauth2-keycloak/health.svg)

```
[![Health](https://phpackages.com/badges/yangze-oauth2-keycloak/health.svg)](https://phpackages.com/packages/yangze-oauth2-keycloak)
```

###  Alternatives

[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2306.4M44](/packages/stevenmaguire-oauth2-keycloak)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

25310.7M82](/packages/thenetworg-oauth2-azure)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1152.8M12](/packages/patrickbussmann-oauth2-apple)[omines/oauth2-gitlab

GitLab OAuth 2.0 Client Provider for The PHP League OAuth2-Client

36779.2k16](/packages/omines-oauth2-gitlab)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
