strebl / ldap-auth

ldap-auth
MIT License
32 stars 15 forks source link

Problem with laravel 5.1 #20

Open montes2012 opened 9 years ago

montes2012 commented 9 years ago

I get this error: ErrorException in LdapAuthUserProvider.php line 117: Undefined index: fieldname

my files

config/auth.php

<?php
return [
        'driver' => 'ldap',
        'model' => App\User::class,
        'table' => 'users',

        'fields' => [
    'username' => 'samaccountname',
    'name' => 'displayName',
    'firstname' => 'givenName',
    'lastname' => 'sn',
    'groups' => 'memberOf',
],

    'password' => [
        'email' => 'emails.password',
        'table' => 'password_resets',
        'expire' => 60,
    ],

];

config/adlap.php

return [
    'account_suffix' => "@inge.local",
    'domain_controllers' => array("172.25.1.50", "172.25.1.51"), 
    'base_dn' => 'DC=ingeo,DC=local',
];
//form login
<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
<input type="password" class="form-control" name="password">
<button type="submit" class="btn btn-primary">Iniciar Sesión</button>
</form>

/routes.php Route::get('auth/login', 'Auth\AuthController@getLogin'); Route::post('auth/login', ['as' =>'auth/login', 'uses' => 'Auth\AuthController@postLogin']);

//AuthController.php

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }
}

I do wrong?

david-nhs commented 9 years ago

I also receive this undefined index error. Do you receive this after successfully authenticating against your LDAP?

cabrerabywaters-zz commented 9 years ago

Any luck with this? I get an "ErrorException in adLDAPCollection.php line 89: Undefined offset: 0" every time I try to login, Could you give us a working example of the config?

I'm trying to authenticate with this test server

  http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

using the email, so my auth.php files looks like this.

 'fields' => [
        'username' => 'samaccountname',
        'name' => 'displayName',
        'firstname' => 'givenName',
        'lastname' => 'sn',
        'groups' => 'memberOf',
        'email'=>'mail'
    ],
    'username_field' => 'email',

Thanks a lot!

strebl commented 9 years ago

Sorry guys for not answering over a month..

Is the issue still present?

carrgilson commented 9 years ago

Hi @strebl, I'm trying to set this up with Laravel 5.1 and I'm getting a very similar error with: ErrorException in LdapAuthUserProvider.php line 117: Undefined index: username Is there something I'm missing or I should be doing here? Scratch that, I needed to add a 'username' column to my database before it would correctly authenticate. It doesn't seem to ever 'touch' the table / database but appears it is required in order to actually authenticate; although I would like it to drop a reference to them into the database somehow.

cmuench commented 8 years ago

@carrgilson @strebl I had the same problem in Laravel 5.1.

I replaced the hard coded username with $this->getUsernameField() inside the method \Ccovey\LdapAuth\LdapAuthUserProvider::validateCredentials.

public function validateCredentials(UserContract $user, array $credentials)
{
    return $this->ad->authenticate($credentials[$this->getUsernameField()], $credentials['password']);
}