PHP code example of rootinc / laravel-saml2-middleware
1. Go to this page and download the library: Download rootinc/laravel-saml2-middleware 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/ */
rootinc / laravel-saml2-middleware example snippets
namespace App\Http\Middleware;
use Closure;
use RootInc\LaravelSaml2Middleware\Saml2 as Saml2;
use Auth;
use Carbon\Carbon;
use App\User;
class AppSaml2 extends Saml2
{
protected function handlecallback($request, Closure $next, $token)
{
$user = Auth::user();
$user->updated_at = Carbon::now();
$user->save();
return parent::handlecallback($request, $next, $token);
}
}
namespace App\Http\Middleware;
use RootInc\LaravelSaml2Middleware\Saml2 as Saml2;
use Auth;
class AppSaml2 extends Saml2
{
protected function redirect($request)
{
if (Auth::user() !== null)
{
return $this->saml2($request);
}
else
{
return parent::redirect($request);
}
}
}
namespace App\Http\Middleware;
use RootInc\LaravelSaml2Middleware\Saml2 as Saml2;
class AppSaml2 extends Saml2
{
protected $login_route = "/";
}
namespace App\Http\Middleware;
use RootInc\LaravelSaml2Middleware\Saml2 as Saml2;
use Auth;
class AppSaml2 extends Saml2
{
//we could overload this if we wanted too.
public function getSaml2Url($email = null)
{
return $this->getAuth()->login(null, [], false, false, true, true, $email);
}
public function saml2(Request $request)
{
$user = Auth::user();
$away = $this->getSaml2Url($user ? $user->email : null);
return redirect()->away($away);
}
}
namespace App\Http\Middleware;
use RootInc\LaravelSaml2Middleware\Saml2 as Saml2;
use Auth;
class AppSaml2 extends Saml2
{
//this is the default behavior
//overwrite to meet your needs
protected function handleTesting(Request $request, Closure $next)
{
$user = Auth::user();
if (!isset($user))
{
return $this->redirect($request, $next);
}
return $this->handlecallback($request, $next, null);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.