Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameID format is hardcoded (AuthnRequest) #54

Closed
01e9 opened this issue Aug 18, 2017 · 2 comments
Closed

NameID format is hardcoded (AuthnRequest) #54

01e9 opened this issue Aug 18, 2017 · 2 comments

Comments

@01e9
Copy link
Author

01e9 commented Aug 21, 2017

Fixed with this code in controller before AuthnRequest generation

// Weird LightSAML event system (Doesn't work with Symfony events)
$this->get('lightsaml.system.event_dispatcher')->addListener(
    Events::BEFORE_ENCRYPT,
    function (GenericEvent $event) {
        /** @var ContextInterface $context */
        $context = $event->getSubject();

        // Add NameIDFormat to AuthnRequest
        if (
            $context instanceof ProfileContext &&
            $context->getProfileId() === 'sso_sp_send_authn_req'
        ) {
            $nameIdFormat = SamlConstants::NAME_ID_FORMAT_PERSISTENT;

            /** @var AuthnRequest $authnRequest */
            $authnRequest = $context->getOutboundContext()->getMessage();
            $authnRequest->setNameIDPolicy(new NameIDPolicy($nameIdFormat, false));
            $authnRequest->getIssuer()->setFormat($nameIdFormat);
        }
    }
);

@01e9 01e9 closed this as completed Aug 21, 2017
@01e9
Copy link
Author

01e9 commented Aug 22, 2017

How to trigger LightSaml events on Symfony event disptacher

Set in config.yml

light_saml_symfony_bridge:
    ...
    system:
        # dispatch LightSaml events on Symfony event dispatcher instead of separate dispatcher
        event_dispatcher: 'event_dispatcher'

So the above event can be hooked as usual

use LightSaml\Event\Events;

public static function getSubscribedEvents()
{
    return [
        Events::BEFORE_ENCRYPT => 'onSamlBeforeEncrypt',
    ];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant