-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature proposal] Event when user isn't found & ability to externally override the user (LDAP example) #11645
[Feature proposal] Event when user isn't found & ability to externally override the user (LDAP example) #11645
Conversation
…over This will make it possible to create the user based on external sources like LDAP, to create the user in the Craft system
src/controllers/UsersController.php
Outdated
if (!$user || $user->password === null) { | ||
// Delay again to match $user->authenticate()'s delay | ||
Craft::$app->getSecurity()->validatePassword('p@ss1w0rd', '$2y$13$nj9aiBeb7RfEfYP3Cum6Revyu14QelGGxwcnFUKXIrQUitSodEPRi'); | ||
return $this->_handleLoginFailure(User::AUTH_INVALID_CREDENTIALS); | ||
|
||
$event = new LoginUserNotFoundEvent([ | ||
'loginName' => $loginName, | ||
]); | ||
$this->trigger(self::EVENT_LOGIN_USER_NOT_FOUND, $event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think this should be triggered in the event that $user
was found but $user->password === null
. Maybe just check for if (!$user)
here, and then add a separate if ($user->password === null)
check after it, keeping the original conditional block inside it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I understand.. Change on it's way
Made a bunch of tweaks – there’s now two events: And merged for 4.2! |
Thanks @brandonkelly ! That was the idea of my PoC and I'm thrilled this is going to be in 4.2. |
4.2.0 is out now with those events ✨ |
Description
In Craft 2, I had developed a LDAP plugin which created users when not found locally in the Craft CMS system. This plugin also had interface settings and options to configure which groups from LDAP should have which permissions in Craft etc.
When a user is not in the Craft CMS system, there is no way (as far I know of) to check an external source, create the user and continue the authentication process, since the user is immediately told the user was not found.
The idea of adding this event is to give plugins the ability to hook in and create the Craft user and continue authentication.
With this update I have managed to create the local user, validate the external password and login to Craft like a normal user.
Explanation
Further development...
Probably you have some thoughts, better ideas, better naming etc.
This is like a PoC proposal to get you involved and to work on improvements.
Like to hear again. Thanks!
Regards, Bert