jotaelesalinas / laravel-adminless-ldap-auth

Authenticate users in Laravel against an adminless LDAP server
MIT License
210 stars 33 forks source link

LDAP+multi Auth Mixed Authetication #11

Closed riyazpt closed 5 years ago

riyazpt commented 6 years ago

I am using Laravel 5.4. There are two types of user in my system. Admin &User. Both have separate database tables .To authenticate ,I have implemented laravel multi auth with custom user provider(mD5) hashed password. Now a situation arose. Same login screen(routing ) for both 'user' and 'admin' . Procedure to Authenticate

  1. Select user type.
  2. If 'admin' selected, go for Ldap authentication. 3.Authenticate user with LDAP server .
  3. If Ldap authetiction fails, go for laravel multi_ ath admin user provider.
  4. If selected user type is 'user' go for multi auth user providerUser

So far I have implemented Laravel multi auth system .

I have made following changes in config in .env file ADLDAP_CONNECTION=default ADLDAP_CONTROLLERS=abc.local ADLDAP_BASEDN=dc=abc,dc=local ADLDAP_USER_ATTRIBUTE=uid ADLDAP_USER_FORMAT=uid=%s,dc=abc,dc=local

Now in LoginController ,

   protected function attemptLogin(Request $request)
    {
        $userdn="abc\\riyas";
        $password="strongpassword@123";
       $mm= Adldap::auth()->attempt($userdn, $password);
 }

which returns TRUE.

but when I try, protected function attemptLogin(Request $request) { $doamin="abc";

    $username = trim($request->input('username', null));
    $password = trim($request->input('password', null));
    $userdn = addslashes($doamin."\\".$username);
    $mm= Adldap::auth()->attempt($userdn, $password);

}

with exact username & password it is not authenticating returns false .

riyazpt commented 6 years ago

My configrations was wrong .I have corrected .Now (Adldap::auth()->attempt() returns true Now I am using NodatabaseSync protected function attemptLogin(Request $request) {

   if(Adldap::auth()->attempt($userdn, $password, $bindAsUser = true)) {

    dd(Auth::user());//Returns Null
    dd(Adldap::search()->users()->find('riyas'));//Returns null

   return true;

} else { return false; } } with exact username & password it is authenticating returns true

I couldn't get exact user Auth::user();after authentication

jotaelesalinas commented 5 years ago

Sorry but this multi-auth setup goes beyond the scope of this tutorial and also beyond my knowledge of Laravel. Closing issue.