Adldap2 / Adldap2-Laravel

LDAP Authentication & Management for Laravel
MIT License
911 stars 184 forks source link

Quickstart.md not working for me #227

Closed martijnimhoff closed 7 years ago

martijnimhoff commented 7 years ago

I'm a bit new to laravel, so please forgive me for asking stupid questions :) I'm using laravel 5.3.

I followed the quickstart readme. Using Adldap::auth()->attempt($username, $password); with a correct password and username works for me. And I can retrieve lists of users etc. However the login form doesn't work. I get the error of wrong credentials.

I think my login controller is still looking for the credentials in the current user model. My login controller currently is the basic laravel login controller

Could someone add the instructions / help me with getting this to work?

stevebauman commented 7 years ago

Hi @martijnimhoff, no problem at all, I'd be glad to help you out! :)

Can you post your config/adldap_auth.php file?

martijnimhoff commented 7 years ago

Thank you. this is my adldap_auth.php


return [
    'connection' => env('ADLDAP_CONNECTION', 'default'),
    'username_attribute' => ['username' => 'samaccountname'],
    'limitation_filter' => env('ADLDAP_LIMITATION_FILTER', ''),
    'login_fallback' => env('ADLDAP_LOGIN_FALLBACK', false),
    'password_key' => env('ADLDAP_PASSWORD_KEY', 'password'),
    'password_sync' => env('ADLDAP_PASSWORD_SYNC', true),
    'login_attribute' => env('ADLDAP_LOGIN_ATTRIBUTE', 'samaccountname'),
    'windows_auth_attribute' => ['samaccountname' => 'AUTH_USER'],
    'bind_user_to_model' => env('ADLDAP_BIND_USER_TO_MODEL', false),
    'sync_attributes' => [
        'name' => 'cn',
    ],
    'select_attributes' => [
        //
    ],
];

And in my .env I've set ADLDAP_PASSWORD_SYNC=true. as well as ADLDAP_ADMIN_USERNAME, ADLDAP_ADMIN_PASSWORD, ADLDAP_LIMITATION_FILTER

stevebauman commented 7 years ago

Looks like you're using a username instead of an email to authenticate:

'username_attribute' => ['username' => 'samaccountname'],

Did you update your create_users_table migration to create a username column instead of email?

You'll also need to update your controller as specified in the quick start doc (below):

If you require logging in by another attribute, such as a username instead of email follow the process below for your Laravel version. Otherwise ignore this step.

Laravel <= 5.2: Inside the generated app/Http/Controllers/Auth/AuthController.php, you'll need to add the protected $username property if you're logging in users by username.

class AuthController extends Controller
{
    protected $username = 'username';

Laravel > 5.3: Inside the generated app/Http/Controllers/Auth/LoginController.php, you'll need to add the public method username():

public function username()
{
    return 'username';
}
martijnimhoff commented 7 years ago

Thanks for your reply! It works now. I added the username() method, updated the fields in the login.blade.php and changed the create_users_table

What was confusing for me is that the LoginController.php is actually a basic laravel file. So it's not generated.

stevebauman commented 7 years ago

Great! Glad you've resolved the issue :).