kidatsy/lightsaml-sp-bundle
Symfony bundle integrating LightSAML as a SAML 2.0 service provider, helping PHP apps configure identity providers and handle SP-initiated login, logout, and assertion processing.
This bundle is a thin Symfony wrapper around LightSAML core that wires up the Service Provider side of a SAML2 Web-Browser SSO flow. Expect zero stars/zero dependents to mean: no community support, treat the source as the documentation. Read DependencyInjection/Configuration.php and Resources/config/services.yml first — those two files tell you every config key and every service ID you can override.
Install (mind the Symfony version — the 2017 release targets Symfony 2.8/3.x, not 4+):
composer require kidatsy/lightsaml-sp-bundle
Also confirm which lightsaml/lightsaml version the bundle pins; the SP API changed across LightSAML 1.x/2.x.
Register the bundle in app/AppKernel.php (Symfony 3 era):
new Kidatsy\SpBundle\SpBundle(),
Configure the SP and IdP. The keys mirror LightSAML's ServiceProvider / IdentityProvider builders — entity ID, assertion consumer endpoint, signing/encryption certificates, and IdP SSO URL + signing cert:
sp_bundle: # verify exact root key in Configuration.php
service_provider:
entity_id: "https://app.example.com/saml/metadata"
assertion_consumer_service_url: "https://app.example.com/saml/acs"
single_logout_service_url: "https://app.example.com/saml/sls"
certificate_file: "%kernel.root_dir%/config/saml/sp.crt"
private_key_file: "%kernel.root_dir%/config/saml/sp.key"
identity_provider:
entity_id: "https://idp.example.com"
single_sign_on_service_url: "https://idp.example.com/sso"
certificate_file: "%kernel.root_dir%/config/saml/idp.crt"
Generate a keypair (openssl req -new -x509 -nodes ...), drop .crt/.key outside the web root, and hand the .crt over to the IdP team.
First use case — SP-initiated login. Hit the bundle's login route (check Resources/config/routing.yml for the exact path, typically something like /_saml/login), authenticate at the IdP, and land back on the ACS endpoint. That round trip is the smoke test: if the ACS accepts the SAMLResponse and returns a mapped principal, the bundle is working.
AuthnRequest, signs it, redirects to the IdP → IdP POSTs a SAMLResponse to the ACS → the bundle validates signature/conditions and gives you a Response object.request_id/InResponseTo check in the Response validation settings. Only do this if the IdP actually drives it, and accept the replay-risk tradeoff.SamlAuthProvider-style service) and, on success, returns a UsernamePasswordToken/PostAuthenticationToken. Keep that glue in your own bundle so upgrades don't break login.$request->request->get('SAMLResponse'), base64-decodes via LightSAML's HTTPPost, validates against the configured IdP, then extracts attributes. Don't re-implement XML-DSig — always let LightSAML validate.Response, not a user. Write a mapper that converts NameID + attribute statements into your User entity, and normalise/whitelist attributes rather than blindly trusting them:
$nameId = $response->getAssertions()[0]->getSubject()->getNameId()->getValue();
$attrs = $response->getAssertions()[0]->getAttributes();
kristophjunge/test-saml-idp in Docker) and drive the flow with a functional test against the ACS endpoint. Unit-test your attribute mapper in isolation.AppKernel, %kernel.root_dir%, and Symfony 3 DI conventions. Budget for a port (services to autowiring, config tree migration, RequestStack) or don't adopt it at all.openssl x509 -in idp.crt -noout -text and check the IdP's KeyDescriptor actually matches.NotBefore/NotOnOrAfter). Keep hosts NTP-synced; most IdPs allow ±5 min, don't exceed that.SignatureExceptions. Enable LightSAML's PSR-3 logger against a Monolog channel and read the actual reason before touching config.InResponseTo / Destination / audience checks each have validation settings. Loosening them to "make it work" is how you get a SAML bypass. Change one at a time, log the original error.services.yml rather than copying the whole bundle. That's the only realistic customisation surface.hslavich/saml-bundle or go straight to OIDC (knpuniversity/oauth2-client-bundle + an IdP that speaks OIDC). If SAML2 is mandated and you're on modern Symfony, this bundle is a research reference, not a dependency.How can I help you explore Laravel packages today?