承接 g4t/keycloak 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

g4t/keycloak

最新稳定版本:1.0.1

Composer 安装命令:

composer require g4t/keycloak

包简介

README 文档

README

The keycloak-guard-laravel package provides an integration between the Keycloak authentication server and a Laravel application. It allows you to use Keycloak as the authentication provider for your Laravel application.

image

Installation You can install the package using Composer:

composer require g4t/keycloak

now publish config file run following command

php artisan vendor:publish

and select g4t\Keycloak\KeycloakGuardServiceProvider provider

Configuration

To configure the package, you need to add your Keycloak server details to your Laravel .env file:

K_REALM_PUBLIC_KEY=
K_LOAD_USER_FROM_DATABASE=true # get user data from database or keycloak
K_USER_PROVIDER_CREDENTIAL=username # This setting specifies the unique column name in your user provider table that will be used to retrieve the user's credentials for authentication.
K_TOKEN_PRINCIPAL_ATTRIBUTE=preferred_username # This setting specifies the key name for the attribute in the Keycloak token that will be used to check against the unique column specified in K_USER_PROVIDER_CREDENTIAL. The attribute should contain the user's unique identifier, such as a username or email address.
K_TOKEN_EXPIRED=false # Enable this when you are sure that you have set the Keycloak server time correctly.

You also need to configure your Laravel application to use the keycloak guard. To do this, add the following to your config/auth.php file:

'guards' => [
    // Other guards...
    
    'keycloak' => [
        'driver' => 'keycloak',
        'provider' => 'users',
    ],
],

'providers' => [
    // Other providers...
    
    'users' => [
        'driver' => 'keycloak',
    ],
],

Usage

Once the package is installed and configured, you can use the keycloak guard to authenticate users in your Laravel application. To authenticate a user, you can use the Auth::guard('keycloak')->attempt($credentials) method, where $credentials is an array of user credentials.

For example:

return auth('keycloak')->attempt([
      'url' => 'http://localhost:8080',
      'realm' => 'realm-name',
      'username' => 'username',
      'password' => 1234,
      'client_id' => 'client_id',
      'client_secret' => 'client_secret',
      'grant_type' => 'password',
]);

You can also use the auth('keycloak')->check() method to check if the user is authenticated:

if (auth('keycloak')->check()) {
    // User is authenticated
} else {
    // User is not authenticated
}

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固