Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Unable to auth user with a NoDatabaseUserProvider #664

@MoiseScalzo

Description

@MoiseScalzo
  • Laravel Version: 5.7
  • Adldap2-Laravel Version: 5.1
  • PHP Version: 7.2
  • LDAP Type: ActiveDirectory

Description:

I'm trying to login with email address (as userprincipalename) and password in a NoDatabaseUserProvider configuration but the Auth::attempt() return always false. On the other hand, Adldap::auth()->attempt($request->userprincipalname, $request->password, $bindAsUser = true); it return true and also Adldap::search()->findBy('userprincipalname', $username) works correctly. So, where I'm wrong? :(
thank you in advance

config/auth.php

'providers' => [
        'users' => [
            'driver' => 'ldap',
        ],
    ],
'guards' => [
        'web' => [
            'driver'   => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver'   => 'token',
            'provider' => 'users',
        ],
    ],

config/ldap_auth.php

'provider'    => Adldap\Laravel\Auth\NoDatabaseUserProvider::class,
'model'       => App\User::class,
'rules'       => [
        Adldap\Laravel\Validation\Rules\DenyTrashed::class,
],
'scopes'     => [
     Adldap\Laravel\Scopes\UpnScope::class,
],
'usernames' => [ 
       'ldap' => [
            'discover'     => 'userprincipalname',
            'authenticate' => 'password',
        ],
        'eloquent' => 'username',
         'windows' => [
            'discover' => 'samaccountname',
            'key' => 'AUTH_USER',
        ],
],

App\Http\Controllers\Auth\LoginController

public static function username()
    {
        return 'userprincipalname';
    }

protected function login(Request $request)
    {
        $credentials = [
            'userprincipalname'    => $request->userprincipalname,
            'password'             => $request->password
        ];

        if (Auth::attempt($credentials)) {
            // not working           
        }
        if ( Adldap::auth()->attempt($request->userprincipalname, $request->password, $bindAsUser = true)) {
             // it works
         }
    }

login.blade.php

<input id="username" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="userprincipalname" value="{{ old('username') }}" required autofocus />
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions