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.

Can't authenticate using Auth::attempt() #683

@matheusyl

Description

@matheusyl
  • Laravel Version: 5.4.36
  • Adldap2-Laravel Version: 3.0.9
  • PHP Version: 5.6.31
  • LDAP Type: OpenLDAP

Description:

I think I have spent almost two days trying to solve this without success, it's time to ask for help.
I keep getting the message "These credentials do not match our records." when using the regular blade form to login the app, so I set a test route to try and debug what the problem could be.

web.php:

Route::get('/test', function() { dd(Adldap::search()->users()->get()); // Works dd(Adldap::search()->where('cn', '=', 'matheusy')->get()); // Works dd(Auth::attempt(['username'=>'matheusy', 'password'=>'password'])); //DOES NOT WORK dd(Adldap::auth()->attempt('cn=matheusy,ou=associado,cn=users,dc=network,dc=ctbc', 'password')); //Works });

As you can see every thing works fine but Auth::attempt keep returning false no matter what.
I've even created a custom schema like proposed in this issue: #642 but it didn't make a difference.
I constantly cleared cofig cache but no success as well (php artisan config:clear)
Maybe i'm just missing some specific configuration.

Here are the configuration files, let me know if you need something else.

.env:

ADLDAP_ACCOUNT_PREFIX= ADLDAP_ACCOUNT_SUFFIX= ADLDAP_CONTROLLERS='ldap.company.com.br' ADLDAP_BASEDN='dc=network,dc=ctbc' ADLDAP_ADMIN_ACCOUNT_SUFFIX= ADLDAP_ADMIN_USERNAME='cn=BINDZOOM,ou=ESPECIAL,cn=Users,dc=network,dc=ctbc' ADLDAP_ADMIN_PASSWORD='password' 

adldap.php

<?php return [ 'connections' => [ 'default' => [ 'auto_connect' => true, 'connection' => Adldap\Connections\Ldap::class, 'schema' => App\Schemas\OpenLDAP::class, 'connection_settings' => [ 'account_prefix' => env('ADLDAP_ACCOUNT_PREFIX', ''), 'account_suffix' => env('ADLDAP_ACCOUNT_SUFFIX', ''), 'domain_controllers' => explode(' ', env('ADLDAP_CONTROLLERS', 'corp-dc1.corp.acme.org corp-dc2.corp.acme.org')), 'port' => env('ADLDAP_PORT', 389), 'timeout' => env('ADLDAP_TIMEOUT', 5), 'base_dn' => env('ADLDAP_BASEDN', 'dc=corp,dc=acme,dc=org'), 'admin_account_suffix' => env('ADLDAP_ADMIN_ACCOUNT_SUFFIX', ''), 'admin_username' => env('ADLDAP_ADMIN_USERNAME', 'username'), 'admin_password' => env('ADLDAP_ADMIN_PASSWORD', 'password'), 'follow_referrals' => false, 'use_ssl' => false, 'use_tls' => false, ], ], ], ];

adldap_auth.php

<?php return [ 'connection' => env('ADLDAP_CONNECTION', 'default'), 'provider' => Adldap\Laravel\Auth\DatabaseUserProvider::class, 'resolver' => Adldap\Laravel\Auth\Resolver::class, 'importer' => Adldap\Laravel\Auth\Importer::class, 'rules' => [ // Denys deleted users from authenticating. Adldap\Laravel\Validation\Rules\DenyTrashed::class, // Allows only manually imported users to authenticate. // Adldap\Laravel\Validation\Rules\OnlyImported::class, ], 'scopes' => [ // Only allows users with a user principal name to authenticate. //Adldap\Laravel\Scopes\UpnScope::class, ], 'usernames' => [ 'ldap' => 'cn', 'eloquent' => 'username', ], 'login_fallback' => env('ADLDAP_LOGIN_FALLBACK', false), 'password_sync' => env('ADLDAP_PASSWORD_SYNC', true), 'windows_auth_attribute' => ['samaccountname' => 'AUTH_USER'], 'sync_attributes' => [ 'name' => 'displayname', 'username' => 'cn', ], ];

auth.php

<?php return [ 'defaults' => [ 'guard' => 'web', 'passwords' => 'users', ], 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], ], 'providers' => [ 'users' => [ 'driver' => 'adldap', // Was 'eloquent'. 'model' => App\User::class, ], ], 'passwords' => [ 'users' => [ 'provider' => 'users', 'table' => 'password_resets', 'expire' => 60, ], ], ];

LoginController.php

<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; class LoginController extends Controller { /*  |--------------------------------------------------------------------------  | Login Controller  |--------------------------------------------------------------------------  |  | This controller handles authenticating users for the application and  | redirecting them to your home screen. The controller uses a trait  | to conveniently provide its functionality to your applications.  |  */ use AuthenticatesUsers; /**  * Where to redirect users after login.  *  * @var string  */ protected $redirectTo = '/home'; /**  * Create a new controller instance.  *  * @return void  */ public function __construct() { $this->middleware('guest')->except('logout'); } public function username() { return 'username'; } }

app.php

<?php return [ 'name' => env('APP_NAME', 'Laravel'), 'env' => env('APP_ENV', 'production'), 'debug' => env('APP_DEBUG', false), 'url' => env('APP_URL', 'http://localhost'), 'timezone' => 'UTC', 'locale' => 'en', 'fallback_locale' => 'en', 'key' => env('APP_KEY'), 'cipher' => 'AES-256-CBC', 'log' => env('APP_LOG', 'single'), 'log_level' => env('APP_LOG_LEVEL', 'debug'), 'providers' => [ /*  * Laravel Framework Service Providers...  */ Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting\BroadcastServiceProvider::class, Illuminate\Bus\BusServiceProvider::class, Illuminate\Cache\CacheServiceProvider::class, Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, Illuminate\Cookie\CookieServiceProvider::class, Illuminate\Database\DatabaseServiceProvider::class, Illuminate\Encryption\EncryptionServiceProvider::class, Illuminate\Filesystem\FilesystemServiceProvider::class, Illuminate\Foundation\Providers\FoundationServiceProvider::class, Illuminate\Hashing\HashServiceProvider::class, Illuminate\Mail\MailServiceProvider::class, Illuminate\Notifications\NotificationServiceProvider::class, Illuminate\Pagination\PaginationServiceProvider::class, Illuminate\Pipeline\PipelineServiceProvider::class, Illuminate\Queue\QueueServiceProvider::class, Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, /*  * Package Service Providers...  */ Laravel\Tinker\TinkerServiceProvider::class, Adldap\Laravel\AdldapServiceProvider::class, Adldap\Laravel\AdldapAuthServiceProvider::class, /*  * Application Service Providers...  */ App\Providers\AppServiceProvider::class, App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, ], 'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, 'Blade' => Illuminate\Support\Facades\Blade::class, 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 'Bus' => Illuminate\Support\Facades\Bus::class, 'Cache' => Illuminate\Support\Facades\Cache::class, 'Config' => Illuminate\Support\Facades\Config::class, 'Cookie' => Illuminate\Support\Facades\Cookie::class, 'Crypt' => Illuminate\Support\Facades\Crypt::class, 'DB' => Illuminate\Support\Facades\DB::class, 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 'Event' => Illuminate\Support\Facades\Event::class, 'File' => Illuminate\Support\Facades\File::class, 'Gate' => Illuminate\Support\Facades\Gate::class, 'Hash' => Illuminate\Support\Facades\Hash::class, 'Lang' => Illuminate\Support\Facades\Lang::class, 'Log' => Illuminate\Support\Facades\Log::class, 'Mail' => Illuminate\Support\Facades\Mail::class, 'Notification' => Illuminate\Support\Facades\Notification::class, 'Password' => Illuminate\Support\Facades\Password::class, 'Queue' => Illuminate\Support\Facades\Queue::class, 'Redirect' => Illuminate\Support\Facades\Redirect::class, 'Redis' => Illuminate\Support\Facades\Redis::class, 'Request' => Illuminate\Support\Facades\Request::class, 'Response' => Illuminate\Support\Facades\Response::class, 'Route' => Illuminate\Support\Facades\Route::class, 'Schema' => Illuminate\Support\Facades\Schema::class, 'Session' => Illuminate\Support\Facades\Session::class, 'Storage' => Illuminate\Support\Facades\Storage::class, 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, 'Adldap' => Adldap\Laravel\Facades\Adldap::class ], ];

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