1. Go to this page and download the library: Download italia/spid-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
italia / spid-laravel example snippets
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
'/spid/*'
];
}
class PrivateController extends Controller
{
/**
* Instantiate a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('spid.auth');
}
}
namespace App\Listeners;
use Italia\SPIDAuth\Events\LoginEvent;
use Italia\SPIDAuth\Events\LogoutEvent;
class SPIDEventSubscriber
{
/**
* Handle SPID login events.
*/
public function onSPIDLogin($event) {
// $event->getSPIDUser() and $event->getIdp() are available here
// your application logic goes here
}
/**
* Handle SPID logout events.
*/
public function onSPIDLogout($event) {
// $event->getSPIDUser() and $event->getIdp() are available here
// your application logic goes here
}
/**
* Register the listeners for the subscriber.
*
* @param Illuminate\Events\Dispatcher $events
*/
public function subscribe($events)
{
$events->listen(
LoginEvent::class, [ SPIDEventSubscriber::class, 'onSPIDLogin' ]
);
$events->listen(
LogoutEvent::class, [ SPIDEventSubscriber::class, 'onSPIDLogout' ]
);
}
}