Skip to content

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

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

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

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:13
@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.

Pull request overview

Improves OIDC login handling for users who were manually matched via Entra UPN when their Moodle username differs (e.g., Moodle username is only the UPN prefix). The change aims to ensure handlelogin() binds the session/token to the matched Moodle username and to reduce case-mismatch problems for Entra UPN lookups.

Changes:

  • Normalize manual-match Entra UPN input to lowercase when saving new matches.
  • Normalize Entra UPN input when searching for manual matches during OIDC login, and bind to the matched Moodle user’s actual username.
  • Add a regression PHPUnit test covering the manually-matched user login flow.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
local/o365/classes/page/acp.php Lowercases manually-entered Entra UPN during manual match creation.
auth/oidc/classes/loginflow/authcode.php Normalizes UPN before matching and binds login to the matched Moodle username.
auth/oidc/tests/loginflow/authcode_test.php Adds regression coverage for first-login completion for manually matched users with differing Moodle username.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread auth/oidc/classes/loginflow/authcode.php Outdated
Comment thread local/o365/classes/page/acp.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