user_load_by_email is case sensitive

Created on 22 April 2025, 2 days ago

Problem/Motivation

Trying out the base module against a Microsoft Entra provider.

I have an account in Drupal and in the tenant, but it after a successful login to the OAuth provider it tells me "User not found in Drupal".

Enabling logging shows

miniorange_oauth_clientController.php, miniorange_oauth_client_mo_login , 155: User does not exists.

Steps to reproduce

Try to login when your email address is not all lower case.

The email attribute returned by Entra is correct but is run through strtolower in

    $account = '';
    if (!empty($email)) {
      $account = user_load_by_mail(strtolower($email));
    }

user_load_by_mail is not case insensitive. See https://www.drupal.org/project/drupal/issues/2876155 🐛 Functions to load user by name or email should be case insensitive Active

Proposed resolution

I altered the code to run

    $account = '';
    if (!empty($email)) {
      $account = user_load_by_mail(strtolower($email));
      if (!isset($account->uid)) {
        $account = user_load_by_mail($email);
      }
    }

This solved the issue for me, but maybe there is a better solution.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇨🇦Canada whikloj

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024