hobbii / socialite-provider
Hobbii OAuth 提供商,适用于 Laravel Socialite
1.2.1
2023-03-22 09:13 UTC
Requires
- php: ^8.1
- ext-json: *
- illuminate/support: ^8.81|^9.0|^10.0
- laravel/socialite: ^5.4
Requires (Dev)
- fakerphp/faker: ^1.18
- friendsofphp/php-cs-fixer: ^3.8
- orchestra/testbench: ^6.0
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
README
一个公共 composer 包,添加 Hobbii 登录提供程序,适用于 Laravel Socialite
composer require hobbii/socialite-provider
安装
添加以下环境变量
HOBBII_LOGIN_SERVICE= HOBBII_CLIENT_ID= HOBBII_CLIENT_SECRET=
用法
使用 socialite 的 hobbii 驱动程序
<?php use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Laravel\Socialite\Facades\Socialite; class AuthController extends Controller { public function redirect(): RedirectResponse { return Socialite::driver('hobbii')->redirect(); } public function callback(Request $request): RedirectResponse { $hobbiiUser = Socialite::driver('hobbii')->user(); $user = User::updateOrCreate([ 'email' => $hobbiiUser->getEmail(), ], [ 'first_name' => Arr::get($hobbiiUser->user, 'first_name'), 'last_name' => Arr::get($hobbiiUser->user, 'last_name'), 'token' => $hobbiiUser->token, 'refresh_token' => $hobbiiUser->refreshToken, ]); Auth::login($user); $request->session()->regenerate(); return redirect()->intended('/'); } }
自定义
通过运行以下命令发布配置文件来自定义设置:
php artisan vendor:publish --provider="Hobbii\SocialiteProvider\SocialiteServiceProvider" --tag=config
在 config/hobbii-socialite.php 中自定义配置。
测试
您可以在 /tests 文件夹中找到测试,并且可以通过运行 ./vendor/bin/phpunit 来执行它们。
静态分析
您可以通过执行 ./vendor/bin/phpstan analyse 来运行 PHPStan。
贡献
有关如何贡献的信息,请参阅 CONTRIBUTING.md
行为准则
Hobbii/SocialiteProvider 采用了 行为准则,我们希望项目参与者遵守。请阅读全文,以便了解哪些行为是可接受的,哪些是不可接受的。
许可证
MIT