How socialiteproviders/saml2 works
1. This repository is a small Laravel Socialite provider package that adds SAML2 as a Socialite driver. It is not an app; it is an adapter layer between Laravel Socialite and a SAML2 implementation.
2. The central runtime boundary is the Provider class. It is the driver implementation that Socialite calls for the SAML2 flow: redirect to the IdP, consume the callback, build the authenticated user object, support logout responses, and expose SP metadata. Most of the repo’s behavior likely lives here.
3. Saml2ExtendSocialite.php is the Laravel-Socialite integration hook for older Laravel setups. It handles the SocialiteWasCalled event and registers the saml2 driver with the Socialite manager. In Laravel 11+, the README shows the same extension is done manually in an app service provider.
4. User.php is the domain object returned after successful SAML login. It carries the canonical Socialite user fields plus SAML-specific data:
- id from SAML NameID
- mapped profile fields such as name/email/first/last/upn
- raw SAML attributes
- the full assertion payload
5. InvalidSignatureException.php and NotSupportedException.php define package-specific failure boundaries. They separate SAML validation and protocol capability errors from normal auth flow, so consumers can distinguish bad assertions from unsupported/invalid configuration or message types.
6. OasisAttributeNameUris.php is a constants/namespace helper for well-known SAML attribute URIs. It exists to make attribute mapping configurable and readable, and it supports the package’s attribute normalization layer rather than business logic.
7. The main data flow is configuration-driven. The application defines a saml2 section in config/services.php with IdP metadata or manual certificate settings, SP ACS/entity IDs, bindings, signing/encryption material, validation settings, and attribute maps. The provider consumes this config to shape SAML requests, responses, and generated metadata.
8. The authentication flow is:
- application calls Socialite::driver('saml2')->redirect()
- provider builds a SAML auth request and sends the browser to the IdP
- IdP returns either a GET redirect or POST callback to the ACS route
- provider validates timestamps/signatures/replay and extracts attributes
- a User object is returned to the app
9. The package explicitly supports two SAML callback bindings: HTTP-Redirect via GET and HTTP-POST via POST. This affects the application boundary, because the callback route must be declared with the chosen HTTP method and POST callbacks may require CSRF exceptions or a route outside web.php.
10. Metadata handling is a second major subsystem. The provider can ingest IdP metadata from a URL or XML string/file, cache it, select a descriptor by entityid, and optionally expose SP metadata at a route. This lets the package act both as SAML service consumer and as metadata publisher for IdP configuration.
11. Validation and security are built into the provider layer rather than pushed to the app. The README describes signature checking, assertion timestamp validation, replay protection via repeated assertion IDs, optional SP signing/encryption certificates, and configurable clock skew and cache TTLs. These are important architecture concerns because they govern trust decisions at the auth boundary.
12. Overall, the repository is best drawn as a thin Laravel package with one integration entry point, one main SAML driver, a user model, constants, and custom exceptions. External dependencies and protocols that materially shape the architecture are Laravel Socialite/SocialiteProviders, SAML2/LightSAML concepts, and optional HTTP metadata retrieval/caching.
Main entry points: Provider.php Provider · Saml2ExtendSocialite.php Socialite hook · User.php User · InvalidSignatureException.php Bad signature
Components 9
Package
Laravel Socialite SAML2 adapter components
- Socialite hook · Registers the saml2 driver on older Laravel/Socialite setups.
Saml2ExtendSocialite.php - Provider · Main SAML2 driver: redirects, handles callbacks, validates responses, builds users, exposes metadata, and supports logout.
Provider.php - User · Authenticated Socialite user enriched with SAML identifiers, mapped profile fields, raw attributes, and assertion data.
User.php - Bad signature · Raised when SAML assertions or signatures fail validation.
InvalidSignatureException.php - Unsupported flow · Raised for unsupported SAML message types or invalid capability/configuration states.
NotSupportedException.php - Attribute URIs · Named SAML attribute URI constants used for readable, configurable claim mapping.
OasisAttributeNameUris.php
External
Runtime and protocol boundaries outside this repository
- Socialite · Laravel Socialite manager and driver contract boundary.
- IdP / ACS · Identity provider, assertion consumer callbacks, and SAML login/logout exchanges.
- Metadata source · IdP metadata fetched from URL, XML, or file and used to configure trust and endpoints.
Connections 9
- Socialite → Socialite hook: event hook · Older Laravel setups register the driver through the SocialiteWasCalled event.
- Socialite → Provider: driver calls · Socialite invokes the provider for redirect, callback handling, and user retrieval.
- Socialite hook → Provider: registers · The extension hook binds the saml2 driver to the provider implementation.
- Provider → IdP / ACS: auth flow · Creates auth requests, consumes callbacks, and handles logout/metadata exchanges.
- Provider → Metadata source: loads metadata · Provider can read and cache IdP metadata from external sources.
- Provider → User: returns · Successful assertions are converted into a Socialite user object.
- Provider → Bad signature: throws · Signature or assertion validation failures are surfaced as package exceptions.
- Provider → Unsupported flow: throws · Unsupported protocol messages or invalid setup are surfaced separately.
- Provider → Attribute URIs: maps claims · Attribute URI constants support readable and configurable SAML claim mapping.