4
4
5
5
use Adldap \Laravel \Traits \ImportsUsers ;
6
6
use Adldap \Models \User ;
7
+ use Adldap \Schemas \ActiveDirectory ;
7
8
use Closure ;
8
9
use Illuminate \Contracts \Auth \Guard ;
9
10
use Illuminate \Database \Eloquent \Model ;
@@ -44,23 +45,22 @@ public function handle(Request $request, Closure $next)
44
45
// Retrieve the SSO login attribute.
45
46
$ auth = $ this ->getWindowsAuthAttribute ();
46
47
48
+ $ key = key ($ auth );
49
+
47
50
// Handle Windows Authentication.
48
- if ($ account = $ request ->server ($ auth )) {
51
+ if ($ account = $ request ->server ($ auth[ $ key ] )) {
49
52
// Usernames will be prefixed with their domain,
50
53
// we just need their account name.
51
54
list ($ domain , $ username ) = explode ('\\' , $ account );
52
55
53
56
// Create a new user LDAP user query.
54
57
$ query = $ this ->newAdldapUserQuery ();
55
58
56
- // Get the username input attributes
57
- $ attributes = $ this ->getUsernameAttribute ();
58
-
59
59
// Get the input key
60
- $ key = key ($ attributes );
60
+ $ key = key ($ auth );
61
61
62
62
// Filter the query by the username attribute
63
- $ query ->whereEquals ($ attributes [ $ key] , $ username );
63
+ $ query ->whereEquals ($ key , $ username );
64
64
65
65
// Retrieve the first user result
66
66
$ user = $ query ->first ();
@@ -70,7 +70,7 @@ public function handle(Request $request, Closure $next)
70
70
71
71
if ($ model instanceof Model && $ this ->auth ->guest ()) {
72
72
// Double check user instance before logging them in.
73
- $ this ->auth ->login ($ user );
73
+ $ this ->auth ->login ($ model );
74
74
}
75
75
}
76
76
}
@@ -97,6 +97,6 @@ public function createModel()
97
97
*/
98
98
protected function getWindowsAuthAttribute ()
99
99
{
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 ' ] );
101
101
}
102
102
}
0 commit comments