A public composer pacakge, adding login provider for Hobbii with Laravel Socialite
composer require hobbii/socialite-provider
Add the following environment variables:
HOBBII_LOGIN_SERVICE=
HOBBII_CLIENT_ID=
HOBBII_CLIENT_SECRET=
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('/');
}
}
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
.
You can find tests in the /tests
folder, and you can run them by using ./vendor/bin/phpunit
.
You can run PHPStan, by executing ./vendor/bin/phpstan analyse
See how to contribute in CONTRIBUTING.md
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.
MIT