hobbii / socialite-provider
Hobbii OAuth provider for 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
A public composer pacakge, adding login provider for Hobbii with Laravel Socialite
composer require hobbii/socialite-provider
Installation
Add the following environment variables:
HOBBII_LOGIN_SERVICE= HOBBII_CLIENT_ID= HOBBII_CLIENT_SECRET=
Usage
Use the hobbii
-driver with socialite:
<?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('/'); } }
Customisation
Publish the configuration file to customise settings, by running
php artisan vendor:publish --provider="Hobbii\SocialiteProvider\SocialiteServiceProvider" --tag=config
Customise the configurations in config/hobbii-socialite.php
.
Testing
You can find tests in the /tests
folder, and you can run them by using ./vendor/bin/phpunit
.
Static analysis
You can run PHPStan, by executing ./vendor/bin/phpstan analyse
Contributing
See how to contribute in CONTRIBUTING.md
Code of Conduct
Hobbii/SocialiteProvider has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.
License
MIT