1. Go to this page and download the library: Download overtrue/laravel-saml 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\Http\Controllers;
use Overtrue\LaravelSaml\Saml;
class SamlController extends Controller
{
public function login() {}
public function acs() {}
public function logout() {}
public function sls() {}
public function metadata() {}
}
//<...>
public function login(Request $request)
{
// Use the default idp in the configuration
return Saml::redirect();
// Or specify the idp name
return Saml::idp($request->get('idp'))->redirect();
}
//<...>
public function acs(Request $request)
{
// Overtrue\LaravelSaml\SamlUser
$samlUser = Saml::getAuthenticatedUser();
// Or specify the idp name
//$samlUser = Saml::idp($request->get('idp'))->getAuthenticatedUser();
$samlUserId = $samlUser->getNameId();
// SamlUser to app User
// $user = User::FirstOrCreate(['email' => $samlUser->getNameId()]);
Auth::set($user);
return redirect('/home')
}
//<...>
public function logout(Request $request)
{
// Use the default IdP in the configuration
return Saml::redirectToLogout();
// Or specify the IdP name
return Saml::idp($request->get('idp'))->redirectToLogout();
}
//<...>
public function sls(Request $request)
{
$auth = Saml::handleLogoutRequest();
// Or specify the IdP name
//$auth = Saml::idp($request->get('idp'))->handleLogoutRequest();
Auth::logout();
return redirect('/home')
}
//<...>
public function metadata(Request $request)
{
if ($request->has('download')) {
return Saml::getMetadataXMLAsStreamResponse();
// or specify a filename to the xml file:
// return Saml::getMetadataXMLAsStreamResponse('sp-metadata.xml');
}
return Saml::getMetadataXML();
}
bash
php artisan vendor:publish --tag=saml-config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.