Skip to content

Added possibility to sign in users by internal user database id#111

Merged
dmitriim merged 3 commits into
catalyst:MOODLE_405_STABLEfrom
MagnusSamuelsson:feature/add-id-auth
Dec 3, 2025
Merged

Added possibility to sign in users by internal user database id#111
dmitriim merged 3 commits into
catalyst:MOODLE_405_STABLEfrom
MagnusSamuelsson:feature/add-id-auth

Conversation

@MagnusSamuelsson

Copy link
Copy Markdown

This update introduces the ability to sign in users by their user ID.
This was required to support our authentication workflow and improves flexibility in how users can be authenticated.

@baffourt

Copy link
Copy Markdown
Contributor

Help me understand this feature, so if i am logging in users from an external service and I pass the right information.
It'll check the internal database and then sign the user in?
A scenario maybe would be great

Thank you

@MagnusSamuelsson

MagnusSamuelsson commented Nov 28, 2025

Copy link
Copy Markdown
Author

Help me understand this feature, so if i am logging in users from an external service and I pass the right information. It'll check the internal database and then sign the user in? A scenario maybe would be great

Thank you

Yes — the feature will use the actual Moodle user ID.

In the original auth_userkey workflow, the external service typically creates the user in Moodle and sets the idnumber field to an identifier that the external system knows. Login URLs are then generated based on that idnumber, not the internal userid.

In our case, the external service already knows the Moodle userid, and we don’t need to manage or set an additional idnumber. Because of that, we can request a login URL directly using the real, internal Moodle userid.

Example:
For a user with userid = 90, you can simply call:
webservice/rest/server.php?wstoken=TOPSECRET&wsfunction=auth_userkey_request_login_url&moodlewsrestformat=json&user[id]=90

Auth_userkey will then return the login URL for that user.

The main benefit of using the internal userid is that it’s stable and cannot be changed, unlike other identifiers such as idnumber.

@dmitriim

Copy link
Copy Markdown
Member

hi @MagnusSamuelsson

Thanks for contributing. Before we can move forward with this change, can you please create a new issue and describe what problem you're trying to solve (you pretty much done that as part of this PR). This would help others to find the issue if they are after the same feature.

Comment thread auth.php
Comment thread auth.php Outdated
Comment thread tests/auth_plugin_test.php Outdated
Comment thread auth.php Outdated
@dmitriim

dmitriim commented Dec 2, 2025

Copy link
Copy Markdown
Member

@MagnusSamuelsson thanks for applying fixes.

It's almost ready to be integrated. With a couple of small tweaks, please also bump the plugin version so a new lang string can be picked up.

CI fails are not related to this changes.

@MagnusSamuelsson

Copy link
Copy Markdown
Author

@MagnusSamuelsson thanks for applying fixes.

It's almost ready to be integrated. With a couple of small tweaks, please also bump the plugin version so a new lang string can be picked up.

CI fails are not related to this changes.

For sure!
Fixing this tomorrow!

@dmitriim dmitriim merged commit 1cdfbfc into catalyst:MOODLE_405_STABLE Dec 3, 2025
3 of 11 checks passed
@MagnusSamuelsson MagnusSamuelsson deleted the feature/add-id-auth branch December 18, 2025 22:48
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.

3 participants