jostkleigrewe/lib-php-eurip-sso 问题修复 & 功能扩展

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

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

jostkleigrewe/lib-php-eurip-sso

最新稳定版本:v0.3.2

Composer 安装命令:

composer require jostkleigrewe/lib-php-eurip-sso

包简介

OIDC Client Library and Symfony Bundle for EURIP SSO

README 文档

README

OIDC Client Library and Symfony Bundle for Single Sign-On.

🇩🇪 Deutsche Version

Features

  • Zero-Code Integration - Complete OIDC auth via configuration only
  • OIDC Authorization Code Flow with PKCE (S256)
  • Device Authorization Grant (RFC 8628) - For CLI, Smart TV, IoT
  • Client Credentials Flow - Machine-to-machine authentication
  • Token Introspection (RFC 7662) - Validate and inspect tokens
  • Session Management - Detect SSO session changes in real-time
  • Auto-Discovery via .well-known/openid-configuration
  • Dual-URL Support for Docker/Kubernetes environments
  • Automatic User Provisioning with Doctrine
  • JWT Signature Verification with key rotation resilience
  • Extensive Event System (9 events)
  • Twig Functions for templates
  • PSR-3 Logging, PSR-18 HTTP Client

Requirements

  • PHP 8.4+
  • Symfony 7.0+ or 8.0+

Installation

composer require jostkleigrewe/lib-php-eurip-sso
// config/bundles.php
Jostkleigrewe\Sso\Bundle\EuripSsoBundle::class => ['all' => true],

Quick Start

1. Configure Bundle

# config/packages/eurip_sso.yaml
eurip_sso:
    issuer: '%env(SSO_ISSUER_URL)%'
    client_id: '%env(OIDC_CLIENT_ID)%'
    redirect_uri: '%env(APP_URL)%/auth/callback'

    user_provider:
        enabled: true
        entity: App\Entity\User
        mapping:
            subject: oidcSubject
            issuer: oidcIssuer

2. Configure Security

# config/packages/security.yaml
security:
    providers:
        app_user_provider:
            id: Jostkleigrewe\Sso\Bundle\Security\DoctrineOidcUserProvider

    firewalls:
        main:
            lazy: true
            provider: app_user_provider
            custom_authenticators:
                - Jostkleigrewe\Sso\Bundle\Security\OidcAuthenticator

Done! Routes available:

  • /auth/login - Start login
  • /auth/callback - SSO callback
  • /auth/logout - Logout (POST with CSRF)
  • /auth/profile - User profile

Twig Functions

Use SSO data directly in your templates:

{% if sso_is_authenticated() %}
    Hello {{ sso_name() ?? sso_email() }}!

    {% if sso_has_role('ROLE_ADMIN') %}
        <a href="/admin">Admin Panel</a>
    {% endif %}

    {% if sso_has_permission('users:edit') %}
        <a href="/users">Manage Users</a>
    {% endif %}
{% endif %}

Available Functions

Function Description
sso_is_authenticated() Check if user is logged in
sso_email() User's email address
sso_name() User's display name
sso_user_id() User's subject (sub claim)
sso_has_role('ROLE_X') Check role (global or client)
sso_has_permission('x:y') Check permission
sso_has_group('group') Check group membership
sso_claim('key', 'default') Get any claim value
sso_supports_session_management() Check if IdP supports session management
sso_session_management_config(5000) Get config for session polling

Logout Component

Secure logout with CSRF protection (requires symfony/ux-twig-component):

{# Simple button #}
<twig:EuripSso:Logout />

{# Styled button #}
<twig:EuripSso:Logout label="Sign Out" class="btn btn-danger" />

{# As link #}
<twig:EuripSso:Logout :asLink="true" />

{# With confirmation #}
<twig:EuripSso:Logout confirm="Are you sure?" />

Session Monitor

Detect SSO session changes (logout from other app):

{% if sso_supports_session_management() %}
    {% include '@EuripSso/components/SessionMonitor.html.twig' %}
{% endif %}

Console Commands

bin/console eurip:sso:cache-warmup        # Pre-fetch OIDC config + JWKS
bin/console eurip:sso:test-connection     # Test OIDC provider connection
bin/console eurip:sso:device-login        # CLI login via Device Code Flow
bin/console eurip:sso:client-credentials  # Get M2M token (Client Credentials)
bin/console eurip:sso:introspect <token>  # Validate and inspect a token

Device Code Flow (RFC 8628)

For CLI tools, Smart TVs, or IoT devices without a browser:

CLI Usage

# Interactive login
bin/console eurip:sso:device-login

# With custom scopes
bin/console eurip:sso:device-login --scopes="openid,profile,roles"

# Output access token for piping
ACCESS_TOKEN=$(bin/console eurip:sso:device-login --output-token)

# Full JSON response
bin/console eurip:sso:device-login --output-json

Programmatic Usage

use Jostkleigrewe\Sso\Client\OidcClient;

// 1. Request device code
$deviceCode = $oidcClient->requestDeviceCode(['openid', 'profile']);

// 2. Show instructions to user
echo "Open: {$deviceCode->verificationUri}\n";
echo "Enter code: {$deviceCode->getFormattedUserCode()}\n";

// 3. Poll for token (blocking)
$tokenResponse = $oidcClient->awaitDeviceToken($deviceCode);

Client Credentials Flow (M2M)

For server-to-server authentication without user interaction:

# Get access token
bin/console eurip:sso:client-credentials

# With specific scopes
bin/console eurip:sso:client-credentials --scopes="api:read,api:write"

# Output token only (for scripts)
TOKEN=$(bin/console eurip:sso:client-credentials --output-token)
// Programmatic usage
$tokenResponse = $oidcClient->requestClientCredentials(['api:read']);
$accessToken = $tokenResponse->accessToken;

Token Introspection (RFC 7662)

Validate and inspect tokens:

bin/console eurip:sso:introspect "eyJhbG..."
bin/console eurip:sso:introspect "eyJhbG..." --output-json
// Programmatic usage
$introspection = $oidcClient->introspectToken($accessToken);

if ($introspection->active) {
    echo "Token valid until: " . $introspection->exp;
    echo "Subject: " . $introspection->sub;
}

Events

Customize the authentication flow with events:

Event When
OidcPreLoginEvent Before redirect to IdP
OidcLoginSuccessEvent After successful login
OidcLoginFailureEvent After failed login
OidcPreLogoutEvent Before logout
OidcUserCreatedEvent New user provisioned
OidcUserUpdatedEvent Existing user updated
OidcTokenRefreshedEvent Token refreshed
OidcBackchannelLogoutEvent Back-channel logout received
OidcFrontchannelLogoutEvent Front-channel logout received
use Jostkleigrewe\Sso\Bundle\Event\OidcLoginSuccessEvent;

#[AsEventListener]
public function onLoginSuccess(OidcLoginSuccessEvent $event): void
{
    $user = $event->user;
    $claims = $event->claims;

    // Custom logic after login
}

Docker/Kubernetes

eurip_sso:
    issuer: 'http://sso-container:8080'        # Internal URL
    public_issuer: 'https://sso.example.com'   # Public URL
    require_https: false                        # Only for local dev!

Documentation

Document Description
Installation Guide Detailed setup instructions
Configuration Full configuration reference
Services Authorization & claims services
Events Customize authentication flow
Flow Diagrams Visual sequence diagrams for all flows
Device Code Flow RFC 8628 for CLI, Smart TV, IoT
M2M Authentication Client Credentials & Token Introspection
Session Management Detect SSO session changes
Standalone Use without Symfony Bundle
Security HTTPS, JWT verification, PKCE
Troubleshooting Common issues and solutions
Upgrade Guide Breaking changes between versions

License

MIT License

jostkleigrewe/lib-php-eurip-sso 适用场景与选型建议

jostkleigrewe/lib-php-eurip-sso 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「Authentication」 「oauth2」 「SSO」 「oidc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jostkleigrewe/lib-php-eurip-sso 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jostkleigrewe/lib-php-eurip-sso 我们能提供哪些服务?
定制开发 / 二次开发

基于 jostkleigrewe/lib-php-eurip-sso 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-22