1. Go to this page and download the library: Download mjollnir/oidconnect-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/ */
namespace App\Auth;
use App\User;
use Furdarius\OIDConnect\Contract\Authenticator;
use Furdarius\OIDConnect\Exception\AuthenticationException;
use Lcobucci\JWT\Token\DataSet;
class PersonAuthenticatorAdapter implements Authenticator
{
/**
* @param DataSet $claims
*
* @return void
*/
public function authUser(DataSet $claims)
{
$email = $claims->get('email');
if (!$email) {
throw new AuthenticationException('User\'s email not present in token');
}
$model = new User(['email' => $email]);
\Auth::setUser($model);
}
}
namespace App\Auth;
use Furdarius\OIDConnect\Contract\Authenticator;
use Illuminate\Support\ServiceProvider;
class AuthenticatorServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Auth::extend('stateless', function () {
return new StatelessGuard();
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(Authenticator::class, function ($app) {
return new PersonAuthenticatorAdapter();
});
}
}