承接 kovah/laravel-socialite-oidc 相关项目开发

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

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

kovah/laravel-socialite-oidc

Composer 安装命令:

composer require kovah/laravel-socialite-oidc

包简介

OpenID Connect OAuth2 Provider for Laravel Socialite

README 文档

README

Laravel Support: v9, v10, v11 PHP Support: 8.1, 8.2, 8.3

Installation & Basic Usage

composer require kovah/laravel-socialite-oidc

Please see the Base Installation Guide, then follow the provider specific instructions below.

Add configuration to config/services.php

'oidc' => [
    'base_url' => env('OIDC_BASE_URL'),
    'client_id' => env('OIDC_CLIENT_ID'),
    'client_secret' => env('OIDC_CLIENT_SECRET'),
    'redirect' => env('OIDC_REDIRECT_URI'),
    
    // Optional: Enable JWT signature verification (default: false)
    'verify_jwt' => env('OIDC_VERIFY_JWT', false),
    
    // Optional: Provide a specific public key for JWT verification
    // If not provided, the key will be fetched from the OIDC provider's JWKS endpoint
    'jwt_public_key' => env('OIDC_JWT_PUBLIC_KEY'),
],

The base URL must be set to the URL of your OIDC endpoint excluding the .well-known/openid-configuration part. For example: If https://auth.company.com/application/linkace/.well-known/openid-configuration is your OIDC configuration URL, then https://auth.company.com/application/linkace must be your base URL.

JWT Signature Verification

By default, this package does not verify the JWT signature of the id_token. According to the OpenID Connect specification, signature verification is not required when TLS is used and the token is transmitted directly from the authorization server to the client.

However, for enhanced security, you can enable JWT signature verification by setting verify_jwt to true in your configuration:

'oidc' => [
    // ... other configuration
    'verify_jwt' => true,
],

When JWT verification is enabled:

  1. Automatic JWKS fetching: The provider will automatically fetch the JSON Web Key Set (JWKS) from your OIDC provider's .well-known/openid-configuration endpoint
  2. Caching: JWKS data is cached for 1 hour to improve performance
  3. Custom public key: Alternatively, you can provide a specific public key using the jwt_public_key option

Example with custom public key:

'oidc' => [
    // ... other configuration
    'verify_jwt' => true,
    'jwt_public_key' => '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
-----END PUBLIC KEY-----',
],

Add provider event listener

Configure the package's listener to listen for SocialiteWasCalled events.

Laravel 11+

In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your AppServiceProvider boot method.

Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
    $event->extendSocialite('oidc', \SocialiteProviders\OIDC\Provider::class);
});

Laravel 10 or below

Add the event to your listen[] array in app/Providers/EventServiceProvider. See the Base Installation Guide for detailed instructions.

protected $listen = [
    \SocialiteProviders\Manager\SocialiteWasCalled::class => [
        // ... other providers
        \SocialiteProviders\OIDC\OIDCExtendSocialite::class.'@handle',
    ],
];

Usage

You should now be able to use the provider like you would regularly use Socialite (assuming you have the facade installed):

return Socialite::driver('oidc')->redirect();

Returned User fields

  • id
  • name
  • email

More fields are available under the user subkey:

$user = Socialite::driver('oidc')->user();

$locale = $user->user['locale'];
$email_verified = $user->user['email_verified'];

Customizing the scopes

You may extend the default scopes (openid email profile) by adding a scopes option to your OIDC service configuration and separate multiple scopes with a space:

'oidc' => [
    'base_url' => env('OIDC_BASE_URL'),
    'client_id' => env('OIDC_CLIENT_ID'),
    'client_secret' => env('OIDC_CLIENT_SECRET'),
    'redirect' => env('OIDC_REDIRECT_URI'),
    
    'scopes' => ['groups', 'roles'],
    // or
    'scopes' => explode(' ', env('OIDC_SCOPES')),
],

Based on the work of jp-gauthier

kovah/laravel-socialite-oidc 适用场景与选型建议

kovah/laravel-socialite-oidc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 129.95k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2024 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 kovah/laravel-socialite-oidc 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 129.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 41
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 4
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-18