Developer Guide
This section provides information for developers who want to extend or customize the SAML authentication functionality.
Architecture Overview
The extension uses the following key components:
AuthenticationService
The Authentication class extends TYPO3's authentication service
and handles:
- SAML response validation
- User lookup and creation
- Authentication status management
Location: Classes/
SamlService
The Saml class provides the interface to the onelogin/php-saml
library:
- SAML configuration management
- SSO redirect handling
- Response parsing
Location: Classes/
SettingsRepository
The Settings provides access to SAML configuration records:
- Auto-discovery by host
- Settings retrieval
Location: Classes/
Middleware
The Deep handles post-authentication redirects:
- Deep link support
- Logout redirect handling
It redirects to the Relay only if the value is a path on the
site (starting with a single /) or an absolute URL with the scheme,
host and port of the current request. Any other value is ignored and the
request is handled as usual.
Location: Classes/
Dependency Injection
All services are registered in the DI container and can be injected into your own classes:
use Netresearch\NrSamlAuth\Service\SamlService;
class MyController
{
public function __construct(
private readonly SamlService $samlService
) {}
}
Extending User Creation
To customize user creation, listen to the PSR-14 events documented in the Events section.
Example: Adding custom user attributes from SAML response:
use Netresearch\NrSamlAuth\Event\BeforeUserCreationEvent;
class CustomUserAttributeListener
{
public function __invoke(BeforeUserCreationEvent $event): void
{
$attributes = $event->getSamlAttributes();
$userData = $event->getUserData();
// Add custom attribute mapping
$userData['custom_field'] = $attributes['customAttribute'][0] ?? '';
$event->setUserData($userData);
}
}