-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Question: howto bind as authenticated user when using the laravel driver? #99
Comments
You cannot stay bound as the authenticated user unless you store their username and password. There is no way around this. PHP is stateless, and will re-connect to connections from scratch on every single request in your application. This means you will need the users credentials on every request that you require a bound LDAP connection to run operations underneath that specific user. This is the purpose for using a static configuration array with a Hope this helps! |
Sorry, I think there is a misunderstanding which is my fault. All I want from ldaprecord is to not switch back to the configured account in ldap.php after authorising, thats why I gave the example in the core docs when the attempt function is called with a 3rd parameter. |
Ok, so I understand properly, you're wanting to bind as the user you are logging in with and run operations underneath them for the duration of the request? Your configured user inside if your Thanks for commenting back! |
You could actually do this by:
// app/Http/Controllers/Auth/LoginController.php
protected function guard()
{
$guard = Auth::guard();
$authenticator = $guard->getProvider()->getLdapUserAuthenticator();
$authenticator->authenticateUsing(function ($user, $password)) {
return $user->getConnection()->auth()->attempt($user->getDn(), $password, $bindAsUser = true);
});
return $guard;
} To do this however, you will need to update to the latest LdapRecord-Laravel version, so run Should work exactly how you're looking to use it. |
Yes, looks exactly what I want! Thank you so much. |
Awesome! Glad that was what you were looking for 😄 Feel free to create another issue if you have any other questions. |
I know this is documented in core docs and it is clear how to achieve this when manually connecting - simply pass true as the 3rd argument to the attempt function call. However, I could not find a way to bind and stay bind as the authenticated user when using the laravel driver. Since there is no call to any attempt function when using the driver...Any ideas?
The text was updated successfully, but these errors were encountered: