24Slides / laravel-saml2

[Laravel 5.4+] An integration to add SSO to your service via SAML2 protocol based on OneLogin toolkit with support of multiple Identity Providers
MIT License
232 stars 70 forks source link

Question: Where to add listeners for events? #65

Open happenpappen opened 1 year ago

happenpappen commented 1 year ago

Hi,

the readme says under "Authentication events", that you should "add listeners on Slides\Saml2\SignedIn and Slides\Saml2\SignedOut events.", but it does not tell where (in which file) one should do that - is there any example showing exactly what to do?

kind regards,

Christoph

chris5tu88s commented 1 year ago

Run this command: php artisan make:listener SsoLoginListener --event=\Slides\Saml2\Events\SignedIn

This will create a new Listener class under the app\Listeners dir.

mohamed-salah-tawfik commented 1 year ago

Auth::login here doesn't work!

chris5tu88s commented 1 year ago

@mohamed-salah-tawfik The same thing happened to me. I could login the user in the listener but once they were redirected to the app, they were not logged in.

Check you have routesMiddleware set in your config/saml2.php file. Mine is set to 'web'. You need to make sure the middleware group is using StartSession in Kernel.php (the 'web' middleware group will do this by default).

imhaggarwal commented 1 year ago

@mohamed-salah-tawfik The same thing happened to me. I could login the user in the listener but once they were redirected to the app, they were not logged in.

Check you have routesMiddleware set in your config/saml2.php file. Mine is set to 'web'. You need to make sure the middleware group is using StartSession in Kernel.php (the 'web' middleware group will do this by default).

Thank you so much. This really helped a lot. To anyone who experiences 419 error, you need to edit your VerifyCsrfToken Middleware.

MichMich commented 1 month ago

I clear up some things for users running laravel 11 or higher:

$middleware->validateCsrfTokens(except: ['saml2/*']);