wmoghes's avatar

LDAP Auth Laravel 5.6

Hi, I has been working on ldap auth and i was following below instructions and it's works but the question now is when i tried to return Auth::user the result always return null so how can i check if the user authenticated or not (I mean how can set auth session when using ldap auth)

thanks in advanced :) https://github.com/Adldap2/Adldap2/blob/master/docs/authenticating.md

try {
        if (Adldap::auth()->attempt($request->email, $request->password, $bindAsUser = true)) {
            dump(Auth::user()); // the result always null
            dd('Credentials were correct');
        } else {
            dd('Credentials were incorrect');
        }

    } catch (\Adldap\Auth\UsernameRequiredException $e) {
        dd('The user didn\'t supply a username');
    } catch (\Adldap\Auth\PasswordRequiredException $e) {
        dd('The user didn\'t supply a password');
    }
0 likes
6 replies
wmoghes's avatar

it's works. thanks bro

I just replaced below code

try {

        if (Adldap::auth()->attempt($request->email, $request->password, $bindAsUser = true)) {
            dump(Auth::user());
            dd('Credentials were correct');
        } else {
            dd('Credentials were incorrect');
        }

    } catch (\Adldap\Auth\UsernameRequiredException $e) {
        dd('The user didn\'t supply a username');
    } catch (\Adldap\Auth\PasswordRequiredException $e) {
        dd('The user didn\'t supply a password');
    }

with this

if (Auth::attempt($request->only(['email', 'password']))) {

        // Returns \App\User model configured in `config/auth.php`.
        $user = Auth::user();
        dump($user);
        dd('Logged in!');
}

and then works. it was my bad :) Thanks again bro. Have a nice day

alexteie's avatar

Is it possible To creatie and ldap auth middleware Just like the auth middleware?

Please or to participate in this conversation.