Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 0071f2a

Browse files
committed
SSO middleware tweaks
1 parent c32aba4 commit 0071f2a

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Config/auth.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@
7777
|
7878
| If your using Apache, this attribute must be named `REMOTE_USER`.
7979
|
80+
| The key of the array is what the user will be discovered from in LDAP.
81+
|
8082
*/
8183

82-
'windows_auth_attribute' => 'AUTH_USER',
84+
'windows_auth_attribute' => ['samaccountname' => 'AUTH_USER'],
8385

8486
/*
8587
|--------------------------------------------------------------------------

src/Middleware/WindowsAuthenticate.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Adldap\Laravel\Traits\ImportsUsers;
66
use Adldap\Models\User;
7+
use Adldap\Schemas\ActiveDirectory;
78
use Closure;
89
use Illuminate\Contracts\Auth\Guard;
910
use 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

Comments
 (0)