cblink / hyperf-socialite
socialite
Installs: 2 565
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^7.4|^8.0
- ext-json: *
- hyperf/contract: ^2.2 || ^3.0
- hyperf/guzzle: ^2.2 || ^3.0
- hyperf/http-message: ^2.2 || ^3.0
- hyperf/http-server: ^2.2 || ^3.0
- league/oauth1-client: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
README
About
cblink/hyperf-socialite 组件衍生于 laravel/socialite 组件的,我们对它进行了一些改造,大部分功能保持了相同。在这里感谢一下 Laravel 开发组,实现了如此强大好用的社会化登陆组件。
Installing
# 安装 composer require cblink/hyperf-socialite -vvv # 创建配置文件 php bin/hyperf.php vendor:publish cblink/hyperf-socialite
Configure
配置文件位于 config/autoload/socialite.php
,如文件不存在可自行创建
<?php return [ // 需要加载的provider 'providers' => [ // \HyperfSocialiteProviders\Feishu\Provider::class, ], 'config' => [ 'facebook' => [ 'client_id' => '', 'client_secret' => '', // 其他provider中需要使用的配置 // ... ], // qq,weixin... ]() ], ];
Usage
控制器中使用
<?php use Cblink\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; } }
支持的列表
Contributing
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
License
MIT