public function handle(Request $request, Closure $next)
{
if (!$this->auth->check()) {
// Retrieve the SSO login attribute.
$auth = $this->getWindowsAuthAttribute();
// Retrieve the SSO input key.
$key = key($auth);
// Handle Windows Authentication.
if ($account = $request->server($auth[$key])) {
// Username's may be prefixed with their domain,
// we just need their account name.
$username = explode('\\', $account);
if (count($username) === 2) {
list($domain, $username) = $username;
} else {
$username = $username[key($username)];
}
if ($user = $this->retrieveAuthenticatedUser($key, $username)) {
$this->auth->login($user);
}
}
}
return $this->returnNextRequest($request, $next);
}