laravel-saml2 icon indicating copy to clipboard operation
laravel-saml2 copied to clipboard

Email Case Sensitivity

Open gbourda opened this issue 1 year ago • 1 comments

Hi, I'm using laravel-saml2 and encountering a case-sensitive email issue where the email returned by the Identity Provider does not match the case of the email stored in our database, causing login failures. Is there a way to configure the package to handle email case insensitivity or any suggestions to fix this? Thanks!

gbourda avatar May 14 '24 13:05 gbourda

You can achieve this by changing the case of the email address returned by the IDP when you handle the SignedIn event.

Within the listener that subscribed to the SignedIn event, you can change the case of the email address before retrieving the user from the database. For example:

public function handle(SignedIn $event)
    {
        // Get the returned user from the IDP
        $samlUser = $event->getSaml2User();

        // Convert to lowercase
        $email = strtolower($samlUser->getUserId());

        // Get user from DB
        $user = User::where('email', $email)->first();

        // Log the user in
        Auth::login($user);
    }

skydudie avatar Jun 11 '24 01:06 skydudie