yaroslawww/laravel-fmc-sso-client

FMC SSO client for laravel framework.

1.3.1 2022-10-18 13:22 UTC

This package is auto-updated.

Last update: 2024-12-18 18:01:03 UTC


README

Packagist License Build Status Code Coverage Scrutinizer Code Quality

If your application uses multiple oAuth providers, it's easier to use a service-independent package like laravel/socialite

Installation

Install the package via composer:

composer require yaroslawww/laravel-fmc-sso-client

Set environment variables

# .env
FMC_SSO_CLIENT_ID="123456"
FMC_SSO_CLIENT_SECRET="RvYvYTDtMDt..."
FMC_SSO_REDIRECT_URL="https://my.app.home/fmc-sso/callback"

Optionally you can publish the config file with:

php artisan vendor:publish --provider="FMCSSOClient\ServiceProvider" --tag="config"

Usage

The fastest way to add functionality is to create a class that extends SSORouter

use FMCSSOClient\Http\Controllers\SSORouter;
use FMCSSOClient\SSOUser;

class FMCSSORouter extends SSORouter
{
    protected function successUserCallback(SSOUser $user): mixed
    {
        $user->getId();
        $user->getName();
        $user->getEmail();
        // add/update database user based on returned object.
    }
    
    // Optional you can add custom scopes
    // public function scopes(): array
    // {
    //     return ['my:custom-scope', 'my:other-scope'];
    // }
}

Then add routes:

// /routes/web.php
Route::middleware( [ 'guest', /*...*/ ] )->group( fn() => \App\Domain\FMCSSO\FMCSSORouter::routes() );

This is it. The default login route is http://my.domain.home/fmc-sso

Credits

  • Think Studio