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

How to use it #1

Open
fmarquis opened this issue Jan 26, 2016 · 19 comments
Open

How to use it #1

fmarquis opened this issue Jan 26, 2016 · 19 comments

Comments

@fmarquis
Copy link

Hi,

thank you for your great work on LightSaml, it allowed me to implement SAML authentication on a Symfony 3 SP very easily !
The only problem I have concern the logout :
I understand that this functionality is not yet integrated in your sp-bundle, and tried to use the "lightSAML-logout" directly.
I managed to create a LogoutRequest that should allow the users to disconnect on the IdP, but I don't see how to use this object...

Is there somewhere a small example of code or documentation explaining how to create a logout request and send it in a symfony environment ?

Thanks in advance,
Franck
(and sorry if my english is not good !)

@fmarquis
Copy link
Author

fmarquis commented Feb 4, 2016

Hi,

I managed to create a logout Post Request which works. Here is my code :


use LightSaml\Model\Protocol\LogoutRequest;
use LightSaml\Model\Assertion\Issuer;
use LightSaml\Binding\SamlPostResponse;
use LightSaml\Model\Context\SerializationContext;

    // Symfony action in a controller
    public function samlLogoutAction() {
        $logoutRequest = new LogoutRequest();
        $destination = $this->get('lightsaml.container.build')->getPartyContainer()->getIdpEntityDescriptorStore()->get(0)->getFirstIdpSsoDescriptor()->getFirstSingleLogoutService()->getLocation();
        $logoutRequest
            ->setDestination($destination)
            ->setID(\LightSaml\Helper::generateID())
            ->setIssueInstant(new \DateTime())
            //the parameter "saml.entity_id" must contain your Service Provider ID
            ->setIssuer(new Issuer($this->getParameter('saml.entity_id')));
        $serializationContext = new SerializationContext();
        $logoutRequest->serialize($serializationContext->getDocument(), $serializationContext);
        $XMLrequest = $serializationContext->getDocument()->saveXML();
        $reponse = new SamlPostResponse($destination, ['SAMLRequest' => base64_encode($XMLrequest)]);
        $reponse->renderContent();
        return $reponse;
    }

Be careful, this code should be changed to work with Redirect Logout, or if you have more than one Logout Service defined by the IdP and the first one is not a Post Logout...
I just hope this can help someone

Regards,
Franck

@INSEAD-asim
Copy link

Hi @tmilos,

I think wiki for this library is missing. Can you help regarding logout route configuration? It is also missing in metadata.xml so our IdP don't know how to logout (except for browser close).

@ntoniazzi
Copy link

@fmarquis I managed to inject the SingleLogoutService in the metadata.xml. Until I find out the proper way to declare it, I'm overriding the lightsaml_sp.metadata route:

lightsaml_sp.metadata:
    path: /metadata.xml
    defaults: { _controller: AcmeSecurityBundle:Security:metadata }
class SecurityController extends Controller
{
    public function metadataAction()
    {
        $router = $this->container->get('router');
        /* @var $router RouterInterface */

        $profile = $this->container->get('ligthsaml.profile.metadata');
        /* @var $profile MetadataProfileBuilder */

        $context = $profile->buildContext();
        /* @var $context ProfileContext */

        $spDescriptor = $context->getOwnEntityDescriptor()->getFirstSpSsoDescriptor();
        $spDescriptor->addSingleLogoutService(
            new SingleLogoutService(
                $router->generate('lightsaml_sp.logout', [], RouterInterface::ABSOLUTE_URL),
                SamlConstants::BINDING_SAML2_HTTP_REDIRECT
            )
        );

        $action = $profile->buildAction();
        /* @var $action CompositeAction */

        $action->execute($context);

        return $context->getHttpResponseContext()->getResponse();
    }
}

But then, I don't know what to do with this library to handle SLO (SP initiated logout and IdP initiated logout).
Does anyone have a small example?

Thanks.

@tmilos
Copy link
Member

tmilos commented Mar 10, 2016

Hello,
This logout lib is not quite finished, the profile actions are missing, but you have all the saml data model classes to serialize/deserialize from bindings, so you would have to create LogoutRequest and LogoutResponse yourself.

Regarding the metadata, see whole lightSAML symfony bridge configuration here. You can set the light_saml_symfony_bridge.own.entity_descriptor_provider.id config to the service id of your class implementing the EntityDescriptorProviderInterface.

You can see how configuration is resolved in LightSamlSymfonyBridgeExtension. First the above mentioned id is looked for, if not provieded, the filename, and finally it defaults to the SimpleEntityDescriptorBuilder - source. You could extend it, or write your own from scratch.

@ntoniazzi
Copy link

It's working well now. Still waiting for a cleaner and bundled way to Sign Out 🙂

Great work 👍
Thanks.

@mathielen
Copy link

@ntoniazzi can you commit your work somewhere so we can see how to integrate it?

@ntoniazzi
Copy link

@mathielen Here are the main files involved in our SingleLogout process. I extracted them from a bundle so there could be something missing.
https://gist.github.com/ntoniazzi/cc9a5f020f9bbde0d9dea7d53ce2e6e1

@INSEAD-asim
Copy link

Thanks @ntoniazzi ! I able to implement logout with your help. I also added signing as our IdP require it for LogoutRequest. The changes include getting own Entity ID and Signature.

Get own Entity ID and Signature:

/** @var OwnContainer $own */
$own = $builder->getOwnContainer();

$ownEntityId    = $own->getOwnEntityDescriptorProvider()->get()->getEntityID();
$ownCredentials = $own->getOwnCredentials();
$ownCredential  = $ownCredentials[0];

/** @var Signature $ownSignature */
$ownSignature = new SignatureWriter($ownCredential->getCertificate(), $ownCredential->getPrivateKey());

Set this in LogoutRequest:

$logoutRequest
    ...
    ->setIssuer(new Issuer($ownEntityId))
    ->setSignature($ownSignature);

Or in LogoutResponse:

$logoutResponse
    ...
    ->setIssuer(new Issuer($ownEntityId))
    ->setSignature($ownSignature);

I hope it will help somebody looking for it. As you mentioned, still looking for cleaner solution.

@INSEAD-asim
Copy link

@tmilos , I think @kaz231 implemented logout functionality at https://github.com/kaz231/SpBundle. Did you tested or have any plan to merge that code?

@gabma
Copy link

gabma commented Mar 17, 2017

@INSEAD-asim @kaz231 Yes! the implemented logout functionality worked perfectly! Helped me integrate it with OKTA.

@tmilos
Copy link
Member

tmilos commented Mar 20, 2017

@INSEAD-asim
Didn't have opportunity to look at PiwikPRO/SpBundle but looked at SpBundle#29 and they look similar. That logout implementation supports only logout with a single IDP, and idea with lightSAML-logout is to be universal implementation of the logout profile with multiple parties for both for SP and IDP. And regarding that very simple case with only one IDP I would rather put it in a separate bundle then together with SpBundle

@gawpertron
Copy link

I've managed to implement logout in the scenario where the is one service provider (SP), however do you have any examples of how to use this when you have multiple SP sessions? Specifically when it's SP initiated? My current set up is a SP sends a LogoutRequest to Identity Provider (IdP) this then loops through all the active sessions $ssoState->getSsoSessions() as $session and LogoutRequest is sent to each SP, however I don't know what response the SPs should return to the IdP on success?

@ntoniazzi
Copy link

@gawpertron When the SP has terminated his logout process, it must return a LogoutResponse to the IdP, which can then call the next SP.
An example here: https://gist.github.com/ntoniazzi/cc9a5f020f9bbde0d9dea7d53ce2e6e1#file-samllogouthandler-php-L76

@gawpertron
Copy link

@ntoniazzi Thanks, that was the guidance I needed. Using your SP implementation I was able to extrapolate an IdP logout service.

@williamhector
Copy link

Does anyone have an example of an implementation from the IdP side they could share?

@axelvnk
Copy link

axelvnk commented Jan 24, 2018

I opened up a PR to integrate the whole logout process in the lightSAML library and SpBundle : lightSAML/lightSAML#106

@circulosmeos
Copy link

circulosmeos commented Jul 16, 2021

Is this project still usable?
Almost 3 years without changes or comments here, and the project hasn't been updated with a wiki in 5 years.

which is the correct way to make a saml single logout with lightSAML library?

I tried @ntoniazzi gist, but I'm getting an error
The "lightsaml.service.binding_factory" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

and also line #144 with
$this->container->getParameter('saml.entity_id')
doesn't resolve that parameter.

It is all very, very much convoluted. This is not what a saml logout bundle experience should provide... It's a pity @axelvnk attempts to integrate this in lightSAML library were rejected.
Anyway, I must thank the programmer/s: this is no easy task :_(

@ntoniazzi
Copy link

Hello,

indeed the lightsaml projects are lethargic, if not dead. The gist you mention is a bit old. You could make it work by removing the direct calls to the container and instead inject the services in the constructor of the SamlLogoutHandler class.

I'm still using the bundles, but I'm thinking on moving to another project. OneLoginSamlBundle seems promising, but I haven't tried it yet.

@AlbertoMontoya81
Copy link

and also line #144 with $this->container->getParameter('saml.entity_id') doesn't resolve that parameter.

Hello:

Line 143 says:
/* here, the SP entity id is a container parameter, change it as you wish */

You need to add the 'saml.entity_id' parameter in your parameters file

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