sindria/oauth2-keycloak

Keycloak OAuth 2.0 客户端提供程序的包装器

1.0.0 2023-04-29 01:29 UTC

This package is not auto-updated.

Last update: 2024-09-29 07:35:14 UTC


README

Keycloak OAuth 2.0 客户端提供程序的包装器,支持认证和授权。

安装

要安装,请使用 composer

composer require sindria/oauth2-keycloak

初始化

$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,
]);

认证

登录

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

注销

$passport->logout();

其他方法

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

授权

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