44
55use Adldap \Laravel \Traits \ImportsUsers ;
66use Adldap \Models \User ;
7+ use Adldap \Schemas \ActiveDirectory ;
78use Closure ;
89use Illuminate \Contracts \Auth \Guard ;
910use Illuminate \Database \Eloquent \Model ;
@@ -44,23 +45,22 @@ public function handle(Request $request, Closure $next)
4445 // Retrieve the SSO login attribute.
4546 $ auth = $ this ->getWindowsAuthAttribute ();
4647
48+ $ key = key ($ auth );
49+
4750 // Handle Windows Authentication.
48- if ($ account = $ request ->server ($ auth )) {
51+ if ($ account = $ request ->server ($ auth[ $ key ] )) {
4952 // Usernames will be prefixed with their domain,
5053 // we just need their account name.
5154 list ($ domain , $ username ) = explode ('\\' , $ account );
5255
5356 // Create a new user LDAP user query.
5457 $ query = $ this ->newAdldapUserQuery ();
5558
56- // Get the username input attributes
57- $ attributes = $ this ->getUsernameAttribute ();
58-
5959 // Get the input key
60- $ key = key ($ attributes );
60+ $ key = key ($ auth );
6161
6262 // Filter the query by the username attribute
63- $ query ->whereEquals ($ attributes [ $ key] , $ username );
63+ $ query ->whereEquals ($ key , $ username );
6464
6565 // Retrieve the first user result
6666 $ user = $ query ->first ();
@@ -70,7 +70,7 @@ public function handle(Request $request, Closure $next)
7070
7171 if ($ model instanceof Model && $ this ->auth ->guest ()) {
7272 // Double check user instance before logging them in.
73- $ this ->auth ->login ($ user );
73+ $ this ->auth ->login ($ model );
7474 }
7575 }
7676 }
@@ -97,6 +97,6 @@ public function createModel()
9797 */
9898 protected function getWindowsAuthAttribute ()
9999 {
100- return Config::get ('adldap_auth.windows_auth_attribute ' , 'AUTH_USER ' );
100+ return Config::get ('adldap_auth.windows_auth_attribute ' , [ActiveDirectory:: ACCOUNT_NAME => 'AUTH_USER ' ] );
101101 }
102102}
0 commit comments