Closed lucaspeeters closed 2 months ago
Hi @lucaspeeters, what session driver are you currently using?
Hey @stevebauman, I use the database for the session driver
'driver' => env('SESSION_DRIVER', 'database'),
I'm using Laravel v11 for the first time, so I've left this setting at default for now.
Thanks @lucaspeeters. Can you try using file
and see if you encounter the same issue?
@stevebauman thank you for your help and your time. I've already tried it, but it doesn't change anything. In addition to changing 'database' to 'file' in session.php, is there anything else to do in other files?
I don't know if this helps but in LoginController when I do a dd(Auth::user()); just before return $this->sendLoginResponse($request); like below:
public function login(Request $request)
{
$this->validateLogin($request);
if (method_exists($this, 'hasTooManyLoginAttempts') &&
$this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
if ($request->hasSession()) {
$request->session()->put('auth.password_confirmed_at', time());
}
dd(auth()->user());
return $this->sendLoginResponse($request);
}
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
I receive this in return:
App\Models\User {#1314 ▼ // app/Http/Controllers/Auth/LoginController.php:88
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: true
#escapeWhenCastingToString: false
#attributes: array:9 [▶]
#original: array:9 [▶]
#changes: []
#casts: array:2 [▶]
#classCastCache: []
#attributeCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
+usesUniqueIds: false
#hidden: array:2 [▶]
#visible: []
#fillable: array:10 [▶]
#guarded: array:1 [▶]
#authPasswordName: "password"
#rememberTokenName: "remember_token"
#ldapUserModel: null
}
Everything seems fine to me, but is it normal for '#ldapUserModel' to equal null?
Thanks @lucaspeeters.
Everything seems fine to me, but is it normal for '#ldapUserModel' to equal null?
Yup that's fine -- that will only be set once it's been retrieved once by the ldap
accessor:
@lucaspeeters Can you confirm that you have an LDAP username and password configured in your .env
as shown in the docs?
https://ldaprecord.com/docs/laravel/v3/configuration#using-a-published-configuration-file
LDAP_USERNAME="cn=user,dc=local,dc=com"
LDAP_PASSWORD=secret
@stevebauman I have all the variables below complete and I'm pretty sure of their values because it worked with the old 'adldap2/adldap2-laravel' package. PS: your package is really incredible, thank you for all your hard work.
LDAP_DEFAULT_HOSTS LDAP_DEFAULT_USERNAME LDAP_DEFAULT_PASSWORD LDAP_DEFAULT_PORT LDAP_DEFAULT_BASE_DN LDAP_DEFAULT_TIMEOUT LDAP_DEFAULT_SSL LDAP_DEFAULT_TLS LDAP_DEFAULT_SASL
Should it be without the “DEFAULT”? If I try the connection fails
@lucaspeeters Thanks for your kind words!
I think there may be an issue here with configuration. It appears there is a published config/ldap.php
file, as well as .env
credentials using dynamic connection configuration. You can only use one or the other, mentioned in the docs here:
https://ldaprecord.com/docs/laravel/v3/configuration#configuration
You can still use your .env
to configure the values inside of the configuration, but if you're prefixing those .env
values with a connection name (in this case, DEFAULT
), then these will conflict with each other.
Try removing _DEFAULT
from all your .env
variables and then re-authenticate:
LDAP_HOSTS=
LDAP_USERNAME=
LDAP_PASSWORD=
LDAP_PORT=
LDAP_BASE_DN=
LDAP_TIMEOUT=
LDAP_SSL=
LDAP_TLS=
LDAP_SASL=
Hey @stevebauman,
Yes I had noticed and changed that over the weekend, I also looked a bit in the Laravel middlewares and finally found a solution. I guess both helped.
Thanks for your answers and your time!
If you have a Code wallet (from getcode), don't hesitate to send me your tip card so I can tip you.
Excellent! 🎉 Glad you're up and running and have resolved the issue. Happy to help @lucaspeeters.
No worries on tipping (I appreciate it though!). I'll always support bug reports regardless of financial incentive. ❤️
Environment:
Bug: After correctly connecting the user to my application and synchronizing with my database, I can't access the authenticated user. Auth::user() returns null.
auth.php
ldap.php
User.php
LoginController.php
UserController.php (Here's where the problem lies)
I remain at your disposal should you require any further information.
Thank you