1. Go to this page and download the library: Download jdlien/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/ */
jdlien / laravel-saml example snippets
use Jdlien\LaravelSaml\Saml;
Saml::configureIdpUsing(function (string $idpName): array {
// Look up the idp config from your DB, tenant store, etc.
return [
'entityId' => '...',
'singleSignOnService' => ['url' => '...'],
// ... see config/saml.php for the full shape
];
});
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Jdlien\LaravelSaml\Saml;
use App\Models\User;
class SamlController extends Controller
{
public function login() {}
public function acs() {}
public function logout() {}
public function sls() {}
public function metadata() {}
}
public function login(Request $request)
{
return Saml::redirect();
}
public function acs(Request $request)
{
$samlUser = Saml::getAuthenticatedUser();
$user = User::firstOrCreate(['email' => $samlUser->getUserId()]);
Auth::login($user);
// getIntendedUrl() validates the SAML RelayState — see "Security" below.
return redirect($samlUser->getIntendedUrl() ?? '/home');
}
public function logout(Request $request)
{
return Saml::redirectToLogout();
}
public function sls(Request $request)
{
$redirect = Saml::handleLogoutRequest();
Auth::logout();
// IdP-initiated logout: handleLogoutRequest() returns a RedirectResponse
// that sends a LogoutResponse back to the IdP. Honor it.
return $redirect ?? redirect('/');
}
public function metadata(Request $request)
{
return Saml::getMetadataXML();
// Or as a streamed download:
// return Saml::getMetadataXMLAsStreamResponse('my-app-saml-metadata.xml');
}
bash
php artisan vendor:publish --tag=saml-config
bash
php artisan make:controller SamlController
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.