leandrose/laravel-keycloak-guard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

leandrose/laravel-keycloak-guard

最新稳定版本:v1.0.0

Composer 安装命令:

composer require leandrose/laravel-keycloak-guard

包简介

A Laravel authentication guard for Keycloak OAuth2 resource servers with token introspection and optional caching support.

README 文档

README

A lightweight Laravel authentication guard for applications acting as OAuth2 / OpenID Connect resource servers using Keycloak.

This package validates Bearer tokens issued by Keycloak by first verifying the JWT signature locally with the realm public key and then confirming the token through the token introspection endpoint.

It also provides optional caching of introspection responses to reduce load on the Keycloak server and improve API performance.

Features

  • Stateless Bearer Token authentication
  • Keycloak OAuth2 / OpenID Connect integration
  • Token validation via local JWT verification plus introspection endpoint
  • Optional introspection caching
  • Cache TTL automatically respecting token expiration (exp)
  • Custom Laravel Guard
  • Works with Laravel 10, 11 and 12

Requirements

  • PHP 8.2+
  • Laravel 10 / 11 / 12
  • Keycloak server with OAuth2 / OpenID Connect enabled
  • Keycloak realm public key available to the application

Version Compatibility

Package Version Laravel 10 Laravel 11 Laravel 12
v1.0

Installation

Install the package via Composer:

composer require leandrose/laravel-keycloak-guard

Publish the configuration file:

php artisan vendor:publish --provider="LeandroSe\\KeycloakGuard\\KeycloakAuthServiceProvider"

Add this to the guards array in config/auth.php:

'defaults' => [
    'guard' => 'api',
    'passwords' => 'users',
],
'guards' => [
    'keycloak' => [
        'driver' => 'keycloak',
        'provider' => 'users',
    ],
],

Configure the Keycloak connection in your environment:

KEYCLOAK_BASE_URL=https://keycloak.example.com
KEYCLOAK_REALM=your-realm
KEYCLOAK_CLIENT_ID=your-client-id
KEYCLOAK_CLIENT_SECRET=your-client-secret
KEYCLOAK_REALM_PUBLIC_KEY="..."

KEYCLOAK_REALM_PUBLIC_KEY can be provided either as a full PEM or as the raw base64 body of the public key.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固