Skip to content

A Public composer package adding a Hobbii OAuth provider for Laravel Socialite

Notifications You must be signed in to change notification settings

hobbii/socialite-provider

Repository files navigation

Hobbii Socialite Provider

Coverage Status Total Downloads Latest Version CI Workflow

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

About

A Public composer package adding a Hobbii OAuth provider for Laravel Socialite

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages