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

Commit 22d8912

Browse files
committed
Allow configurable windows auth attributes
1 parent fa9756f commit 22d8912

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Config/auth.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@
6262

6363
'login_attribute' => 'samaccountname',
6464

65+
/*
66+
|--------------------------------------------------------------------------
67+
| Windows Auth Attribute (SSO)
68+
|--------------------------------------------------------------------------
69+
|
70+
| The windows authentication attribute is the name of the server variable
71+
| that is filled when SSO authentication is performed.
72+
|
73+
| This is only used in conjunction with the Adldap\Laravel\Middleware\WindowsAuthenticate
74+
| middleware.
75+
|
76+
| If your using Windows authentication this attribute must be named `AUTH_USER`.
77+
|
78+
| If your using Apache, this attribute must be named `REMOTE_USER`.
79+
|
80+
*/
81+
82+
'windows_auth_attribute' => 'AUTH_USER',
83+
6584
/*
6685
|--------------------------------------------------------------------------
6786
| Bind User to Model

src/Middleware/WindowsAuthenticate.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Auth\Guard;
99
use Illuminate\Database\Eloquent\Model;
1010
use Illuminate\Http\Request;
11+
use Illuminate\Support\Facades\Config;
1112

1213
class WindowsAuthenticate
1314
{
@@ -40,8 +41,11 @@ public function __construct(Guard $auth)
4041
*/
4142
public function handle(Request $request, Closure $next)
4243
{
44+
// Retrieve the SSO login attribute.
45+
$auth = $this->getWindowsAuthAttribute();
46+
4347
// Handle Windows Authentication.
44-
if ($account = $request->server('AUTH_USER')) {
48+
if ($account = $request->server($auth)) {
4549
// Usernames will be prefixed with their domain,
4650
// we just need their account name.
4751
list($domain, $username) = explode('\\', $account);
@@ -83,4 +87,14 @@ public function createModel()
8387
{
8488
$this->auth->model();
8589
}
90+
91+
/**
92+
* Returns the windows authentication attribute.
93+
*
94+
* @return string
95+
*/
96+
protected function getWindowsAuthAttribute()
97+
{
98+
return Config::get('adldap_auth.windows_auth_attribute', 'AUTH_USER');
99+
}
86100
}

0 commit comments

Comments
 (0)