Skip to content

Fix OIDC login for manually matched users with mismatching Entra username - #3364

Open
Lai Wei (weilai-irl) wants to merge 1 commit into
MOODLE_500_STABLEfrom
wip-135651-m500
Open

Fix OIDC login for manually matched users with mismatching Entra username#3364
Lai Wei (weilai-irl) wants to merge 1 commit into
MOODLE_500_STABLEfrom
wip-135651-m500

Conversation

@weilai-irl

Copy link
Copy Markdown
Collaborator

Manually matched users are keyed by Entra UPN, which often differs from the Moodle username. handlelogin() found the matched user but then discarded it, continuing with the UPN as the username and failing with "User not found in Moodle." Now it binds to the matched user's actual username instead. Also normalizes entraidupn casing on write and read to avoid case-mismatch failures.

Copilot AI lite review requested due to automatic review settings August 6, 2026 15:14
@weilai-irl Lai Wei (weilai-irl) self-assigned this Aug 6, 2026
@weilai-irl Lai Wei (weilai-irl) added this to the 2026-03 milestone Aug 6, 2026
@weilai-irl Lai Wei (weilai-irl) linked an issue Aug 6, 2026 that may be closed by this pull request
@weilai-irl Lai Wei (weilai-irl) changed the title fix OIDC login for manually matched users with mismatching Entra username Fix OIDC login for manually matched users with mismatching Entra username Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new lowercasing in match lookup can break legacy mixed-case entraidupn rows on case-sensitive DBs, and the new test should ensure global $_GET cleanup via try/finally to prevent cross-test pollution.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR fixes an OIDC login edge case where a manually matched user (keyed by Entra UPN) could be found but then effectively ignored when the Moodle username differs from the UPN, causing login failures. It also aims to reduce case-mismatch issues by normalizing entraidupn casing during manual matching and lookup.

Changes:

  • Normalize manually entered entraidupn to lowercase when saving user connections.
  • During OIDC auth-code login, bind to the matched Moodle user’s actual username (instead of the Microsoft-derived identifier) when the matched user is already auth='oidc'.
  • Add a regression PHPUnit test covering the “manual match + differing username” login flow.
File summaries
File Description
local/o365/classes/page/acp.php Lowercases manually entered Entra UPN when creating a manual match.
auth/oidc/classes/loginflow/authcode.php Normalizes match lookup input and binds $username to the matched Moodle user’s username when appropriate.
auth/oidc/tests/loginflow/authcode_test.php Adds regression coverage for manually matched users whose Moodle username differs from Entra UPN.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread auth/oidc/classes/loginflow/authcode.php Outdated
Comment thread auth/oidc/tests/loginflow/authcode_test.php Outdated
…name

Manually matched users are keyed by Entra UPN, which often differs from the Moodle username. handlelogin() found the matched user but then discarded it, continuing with the UPN as the username and failing with "User not found in Moodle." Now it binds to the matched user's actual username instead. Also normalizes entraidupn casing on write and read to avoid case-mismatch failures.
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

Successfully merging this pull request may close these issues.

User Account Matching and Completion Authentication

2 participants