aimilink / hyperf-socialite
socialite
3.0.4
2023-09-21 08:03 UTC
Requires
- php: ^7.4|^8.0|^8.1
- ext-json: *
- hyperf/contract: ^3.0
- hyperf/guzzle: ^3.0
- hyperf/http-message: ^3.0
- hyperf/http-server: ^3.0
- league/oauth1-client: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
This package is not auto-updated.
Last update: 2024-09-20 12:46:42 UTC
README
关于
Aimilink/hyperf-socialite 组件由 cblink/hyperf-socialite 组件衍生而来,已升级组件版本。
安装
# 安装 composer require Aimilink/hyperf-socialite -vvv # 创建配置文件 php bin/hyperf.php vendor:publish Aimilink/hyperf-socialite
配置
配置文件位于 config/autoload/socialite.php
,如果文件不存在,可以自行创建。
<?php return [ // 需要加载的provider 'providers' => [ // \HyperfSocialiteProviders\Feishu\Provider::class, ], 'config' => [ 'facebook' => [ 'client_id' => '', 'client_secret' => '', // 其他provider中需要使用的配置 // ... ], // qq,weixin... ]() ], ];
使用方法
组件已提供许多支持的社会化登录组件,只需将其配置到 config/autoload/listeners.php
中即可。
return [ HyperfSocialiteProviders\Facebook\FacebookExtendSocialite::class, ];
在控制器中使用
<?php use Aimilink\Hyperf\Socialite\Contracts\SocialiteInterface; class Controller { /** * @param SocialiteInterface $socialite * @return \Hyperf\HttpServer\Contract\ResponseInterface */ public function redirectToProvider(SocialiteInterface $socialite) { // 重定向跳转 $redirect = $socialite->driver('facebook')->redirect(); // 使用新的配置跳转 $socialite->driver('facebook')->setConfig([ 'client_id' => 'xxx', 'client_secret' => 'xxxx', ]) return $redirect; } /** * @param SocialiteInterface $socialite */ public function handleProviderCallback(SocialiteInterface $socialite) { // 获取用户信息 $user = $socialite->driver('facebook')->user(); // // $user->token; } }
支持的列表
贡献
您可以通过以下三种方式之一进行贡献
代码贡献过程并不正式。您只需确保遵循PSR-0、PSR-1和PSR-2编码规范。任何新的代码贡献都必须附带适用的单元测试。
许可
MIT