99use Adldap \Laravel \Events \Authenticated ;
1010use Adldap \Laravel \Events \Authenticating ;
1111use Adldap \Laravel \Events \AuthenticationFailed ;
12- use Adldap \Laravel \Auth \DatabaseUserProvider ;
1312use Adldap \Laravel \Auth \NoDatabaseUserProvider ;
13+ use Illuminate \Support \Facades \Auth ;
1414use Illuminate \Support \Facades \Event ;
1515use Illuminate \Support \Facades \Config ;
16+ use Illuminate \Contracts \Auth \UserProvider ;
1617use Illuminate \Contracts \Auth \Authenticatable ;
1718
1819class UserResolver implements ResolverInterface
@@ -25,7 +26,7 @@ class UserResolver implements ResolverInterface
2526 protected $ ldap ;
2627
2728 /**
28- * The LDAP connection to utilize.
29+ * The name of the LDAP connection to utilize.
2930 *
3031 * @var string
3132 */
@@ -38,7 +39,7 @@ public function __construct(AdldapInterface $ldap)
3839 {
3940 $ this ->ldap = $ ldap ;
4041
41- $ this ->setConnection ($ this ->getAuthConnection ());
42+ $ this ->setConnection ($ this ->getLdapAuthConnectionName ());
4243 }
4344
4445 /**
@@ -66,12 +67,10 @@ public function byCredentials(array $credentials = [])
6667 return ;
6768 }
6869
69- $ provider = Config::get ('adldap_auth.provider ' , DatabaseUserProvider::class);
70-
7170 // Depending on the configured user provider, the
7271 // username field will differ for retrieving
7372 // users by their credentials.
74- if ($ provider == NoDatabaseUserProvider::class ) {
73+ if ($ this -> getAppAuthProvider () instanceof NoDatabaseUserProvider) {
7574 $ username = $ credentials [$ this ->getLdapDiscoveryAttribute ()];
7675 } else {
7776 $ username = $ credentials [$ this ->getEloquentUsernameAttribute ()];
@@ -114,7 +113,7 @@ public function authenticate(User $user, array $credentials = [])
114113
115114 Event::fire (new Authenticating ($ user , $ username ));
116115
117- if ($ this ->getProvider ()->auth ()->attempt ($ username , $ password )) {
116+ if ($ this ->getLdapAuthProvider ()->auth ()->attempt ($ username , $ password )) {
118117 Event::fire (new Authenticated ($ user ));
119118
120119 return true ;
@@ -130,7 +129,7 @@ public function authenticate(User $user, array $credentials = [])
130129 */
131130 public function query () : Builder
132131 {
133- $ query = $ this ->getProvider ()->search ()->users ();
132+ $ query = $ this ->getLdapAuthProvider ()->search ()->users ();
134133
135134 $ scopes = Config::get ('adldap_auth.scopes ' , []);
136135
@@ -192,19 +191,29 @@ protected function getPasswordFromCredentials($credentials)
192191 *
193192 * @throws \Adldap\AdldapException
194193 *
195- * @return \Adldap\Connections\ ProviderInterface
194+ * @return ProviderInterface
196195 */
197- protected function getProvider () : ProviderInterface
196+ protected function getLdapAuthProvider () : ProviderInterface
198197 {
199198 return $ this ->ldap ->getProvider ($ this ->connection );
200199 }
201200
201+ /**
202+ * Returns the default guards provider instance.
203+ *
204+ * @return UserProvider
205+ */
206+ protected function getAppAuthProvider () : UserProvider
207+ {
208+ return Auth::guard ()->getProvider ();
209+ }
210+
202211 /**
203212 * Returns the connection name of the authentication provider.
204213 *
205214 * @return string
206215 */
207- protected function getAuthConnection ()
216+ protected function getLdapAuthConnectionName ()
208217 {
209218 return Config::get ('adldap_auth.connection ' , 'default ' );
210219 }
0 commit comments