sindria/oauth2-keycloak

A wrapper for the Keycloak OAuth 2.0 Client Provider

Maintainers

Package info

github.com/SindriaInc/oauth2-keycloak

pkg:composer/sindria/oauth2-keycloak

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

1.0.0 2023-04-29 01:29 UTC

This package is not auto-updated.

Last update: 2026-03-01 15:12:56 UTC


README

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

Installation

To install, use composer:

composer require sindria/oauth2-keycloak

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

Login

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

logout

$passport->logout();

Other Methds

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

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);