@@ -13,6 +13,13 @@ class AdldapAuthUserProvider extends EloquentUserProvider
1313{
1414 use ImportsUsers;
1515
16+ /**
17+ * The authenticated LDAP user.
18+ *
19+ * @var User
20+ */
21+ protected $ user = null ;
22+
1623 /**
1724 * {@inheritdoc}
1825 */
@@ -40,8 +47,8 @@ public function retrieveByCredentials(array $credentials)
4047 {
4148 $ user = $ this ->authenticateWithCredentials ($ credentials );
4249
43- // If the user is an Adldap User model instance .
44- if ($ user instanceof User) {
50+ // Check if we've authenticated and retrieved an AD user .
51+ if ($ user instanceof User && $ this -> user = $ user ) {
4552 // Retrieve the password from the submitted credentials.
4653 $ password = $ this ->getPasswordFromCredentials ($ credentials );
4754
@@ -61,9 +68,9 @@ public function retrieveByCredentials(array $credentials)
6168 */
6269 public function validateCredentials (Authenticatable $ user , array $ credentials )
6370 {
64- if ( $ this -> authenticateWithCredentials ( $ credentials )) {
65- // We've authenticated successfully, we'll finally
66- // save the user to our local database .
71+ // Check if we already have an authenticated AD user.
72+ if ( $ this -> user instanceof User) {
73+ // We'll save the model in case of changes .
6774 $ this ->saveModel ($ user );
6875
6976 return true ;
@@ -138,7 +145,9 @@ protected function authenticateWithCredentials(array $credentials = [])
138145 {
139146 // Make sure we're connected to our LDAP server before we run any operations.
140147 if ($ this ->isConnected ()) {
141- // Retrieve the Adldap user.
148+ // Due to having the ability of choosing which attribute we login users
149+ // with, we actually need to retrieve the user from our LDAP server
150+ // before hand so we can retrieve these attributes.
142151 $ user = $ this ->newAdldapUserQuery ()->where ([
143152 $ this ->getUsernameValue () => $ this ->getUsernameFromCredentials ($ credentials )
144153 ])->first ();
0 commit comments