aacotroneo / laravel-saml2

A Laravel 5 package for Saml2 integration as a SP (service provider) based on the simple OneLogin toolkit
MIT License
564 stars 237 forks source link

Can we catch the SAML user from SAMLLogoutEvent listener #225

Open kalana3029 opened 4 years ago

kalana3029 commented 4 years ago

Hi, I need to identified the user which user was logout from the SAML, In SAMLLogoutEvent listener return only Idp name, How can i get the related user from there.

danmichaelo commented 4 years ago

You can use the authenticated user from the session :) Here's a simple Saml2Logout handler:

<?php

namespace App\Listeners;

use Aacotroneo\Saml2\Events\Saml2LogoutEvent;

class Saml2Logout
{
    /**
     * Handle the event.
     *
     * @param Saml2LogoutEvent $event
     *
     * @return void
     */
    public function handle(Saml2LogoutEvent $event)
    {
        $user = auth()->user();
        if ($user) {
            \Log::info("User {$user->id} logged out")
        }
        auth()->logout();
        session()->invalidate();
    }
}
kalana3029 commented 3 years ago

@danmichaelo Thing is, I am using token-based authentication. Can we get the logout user's email from the Saml2LogoutEvent ?