onelogin/php-saml
PHP toolkit for adding SAML 2.0 SSO to your app. Handles login/logout, assertion processing, metadata generation, and signature/encryption validation, with strict security options and PHP 7.3+ (4.x) or older PHP support via branches.
acs.php, sls.php, metadata.php)./saml/acs, /saml/sls) with minimal boilerplate. Middleware can pre-process SAML requests/responses.config/ system can centralize SAML settings.xmlseclibs, openssl) are standard in Laravel’s ecosystem. Potential conflicts with mcrypt (deprecated in PHP 7.2+) can be mitigated via ext-openssl for encryption.strict: true, SHA-256 signatures) to mitigate replay/redirect attacks. Laravel’s middleware can enforce these checks pre/post-SAML processing.storage/ or environment variables). Key rollover (e.g., sp_new.crt) needs automation (e.g., cron jobs or Laravel tasks).curl) may need Laravel-specific HTTP clients (e.g., Guzzle).auth:guard() or custom session drivers.OneLogin_Saml2_Response.Route::post('/saml/acs', [SamlController::class, 'handleAcs'])).app()->bind(OneLogin_Saml2_Auth::class, fn() => new OneLogin_Saml2_Auth($settings))).config/saml.php (merge with settings_example.php).php-openssl, php-xml (enabled by default in Laravel).php-curl (for IdP metadata parsing), php-mcrypt (deprecated; replace with openssl for encryption).composer require onelogin/php-saml:^4.0 # For PHP 7.3+/8.x
settings_example.php → config/saml.php.storage_path() or environment variables.$settings = [
'strict' => true,
'sp' => [
'entityId' => env('SAML_ENTITY_ID'),
'x509cert' => file_get_contents(storage_path('certs/sp.crt')),
'privateKey' => file_get_contents(storage_path('certs/sp.key')),
],
'security' => [
'signatureAlgorithm' => 'sha256',
'digestAlgorithm' => 'sha256',
],
];
SamlController to handle acs, sls, and metadata:
public function handleAcs(Request $request) {
$auth = app(OneLogin_Saml2_Auth::class);
$requestId = $auth->validateAuthnRequest();
// Process SAML response and redirect to Laravel route.
}
Route::post() for POST bindings (handle raw POST data).SamlMiddleware to validate SAML responses before processing:
public function handle($request, Closure $next) {
$auth = app(OneLogin_Saml2_Auth::class);
if (!$auth->isValidResponse($request->get('SAMLResponse'))) {
abort(403, 'Invalid SAML response');
}
return $next($request);
}
Auth::loginUsingId($auth->getAttributes()['email']);
redirect()->to() with RelayState.Request object can access $_POST['SAMLResponse'].storage/app/certs/ or environment variables over vendor/ to avoid Composer update risks.sls.php endpoint.onelogin/php-saml for security patches (e.g., CVE-2025-66475). Use Composer’s update cautiously (back up config/saml.php).sp.crt/sp.key.logs/saml.log using Monolog:
$auth->setDebugLogFile(storage_path('logs/saml.log'));
$auth->setDebugLogLevel(OneLogin_Saml2_Utils::LOG_DEBUG);
report() method or Sentry.debugLogLevel: LOG_DEBUG) for SAML validation errors.dd() or dump() to inspect $auth->getLastErrorReason().acs.php/sls.php are stateless (no shared memory). Use Laravel’s queue system for async processing if needed.| Failure Scenario | Impact | Mitigation | |--------------------------------|--------------------------------------
How can I help you explore Laravel packages today?