Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tavares's avatar

Active Directory Single Sign on

Hi,

In my laravel project i need to authenticate user with the user logged in windows.

I install the Adldap2 : https://github.com/Adldap2/Adldap2-Laravel

And i create the auth controller:

php artisan make:auth

But now i don't know how to get the authenticated user on windows and where i verify that. I have to obtain the user logged in the system and then verify if exists in table database.

Thanks

0 likes
3 replies
mhankins's avatar

First use the Facade to make sure it's setup correctly and communicating with AD.

dd(Adldap::getDefaultProvider()->search()->users()->find('mhankins'));

Obviously, change the username you're trying to search for, but if you can't get past this point then you have a configuration issue. Refer to the documentation on that one.

Then you can simply authorize against it just like you normally would.

        if (Auth::attempt($credentials, $request->has('remember'))) {
faraz73's avatar

@mhankins how to check user authentication ? Like :

Adldap::auth()->check()

check method is not exists tho .. i'm assuming that user no longer be 'guest' .. so we can check it in our controllers and routes. should we create new middleware ?

tavares's avatar

Ok. I'm using a mssql database that already have a user table implemented named us. How can use this table and don't the user laravel table?

I put that code into LoginController constructer?

public function __construct()
    {
      $email = Input::get('email');
      $password = Input::get('password');
      $remember = Input::get('remember');

      $adUser = Adldap::getDefaultProvider()->search()->users()->find($email);
      if (Auth::attempt(['email' => $email, 'password' => $password], $remember))
      {
          // Authentication passed...
          return redirect()->intended('dashboard');
      }
    }

Thanks for helping me @mhankins

Please or to participate in this conversation.