Installation
composer require conduction/samlbundle
Enable the bundle in config/bundles.php:
return [
// ...
Conduction\SamlBundle\ConductionSamlBundle::class => ['all' => true],
];
Configuration
Copy the default config to config/packages/conduction_saml.yaml:
php bin/console make:config conduction_saml
Update with your Identity Provider (IdP) metadata (XML or URL) and Service Provider (SP) settings (entity ID, private key, certificate).
First Use Case
# config/routes.yaml
conduction_saml_login:
path: /login/saml
controller: conduction_saml.controller
conduction_saml.yaml:
sp:
acs_url: "https://your-app.com/login/saml/callback"
Verify Setup Run the SAML validator:
php bin/console conduction:saml:validate
Test with a browser or Postman by accessing /login/saml.
User Authentication Flow
use Conduction\SamlBundle\Security\SamlAuthenticator;
// In a controller or event listener
$authenticator = new SamlAuthenticator();
return $authenticator->start($request, $options);
User Provisioning
SamlUserProvider to fetch user attributes from the SAML response:
$userProvider = $container->get('conduction_saml.user_provider');
$user = $userProvider->loadUserBySAMLResponse($samlResponse);
SamlUserProvider or use a custom mapper).Session Management
# security.yaml
firewalls:
main:
saml: true
Symfony Security Integration Configure the firewall to use SAML authentication:
security:
providers:
saml_provider:
id: conduction_saml.user_provider
firewalls:
main:
saml: ~
Custom Attribute Mapping
Override the default attribute mapper in services.yaml:
conduction_saml.user_provider:
class: App\Security\CustomSamlUserProvider
arguments:
- '@conduction_saml.attribute_mapper'
- '@conduction_saml.user_mapper'
Metadata Handling Dynamically fetch IdP metadata from a URL:
idp:
metadata_url: "https://idp.example.com/metadata"
Logging and Debugging
Enable debug mode in conduction_saml.yaml:
debug: true
Log SAML messages to var/log/saml.log.
Certificate and Key Configuration
sp:
private_key: "%kernel.project_dir%/config/saml/sp-key.pem"
certificate: "%kernel.project_dir%/config/saml/sp-cert.pem"
ACS URL Mismatch
acs_url in conduction_saml.yaml must match the URL used in the IdP configuration. A mismatch will cause authentication to fail silently.conduction:saml:validate to check URL consistency.Attribute Mapping Issues
email, firstName) are not mapping correctly, verify:
$samlResponse = $request->get('SAMLResponse');
file_put_contents('saml_response.xml', base64_decode($samlResponse));
Time Synchronization
Caching Metadata
metadata_url, the bundle caches metadata by default. Clear the cache if IdP metadata changes:
php bin/console cache:clear
Testing Locally
Custom Error Handling
SamlExceptionListener to handle SAML errors gracefully:
use Conduction\SamlBundle\Event\SamlExceptionEvent;
$eventDispatcher->addListener(SamlExceptionEvent::class, function (SamlExceptionEvent $event) {
$event->setResponse(new RedirectResponse('/login?error=saml'));
});
Logout Functionality
sp:
single_logout_url: "https://your-app.com/logout/saml"
Performance
$metadata = $container->get('conduction_saml.metadata');
$metadata->load(); // Explicitly load metadata
Bundle Updates
conduction/samlbundle as it’s actively maintained. Check the changelog for breaking changes.How can I help you explore Laravel packages today?