Closed shaneho closed 6 years ago
Hi @shaneho,
This is actually due to using the Postgre database - as its queries are case sensitive rather than MySQL where they are case insensitive.
You will have to normalize your account names before authenticating them with a strtolower()
before passing them into the Auth::attempt()
command.
You will also likely need to extend the built in adldap:import
command with your own to be able to normalize usernames prior to import so they sync properly and override the getUserCredentials
method:
namespace App\Console\Commands;
use Adldap\Laravel\Commands\Console\Import;
class LdapImport extends Import
{
protected function getUserCredentials()
{
$resolver = Resolver::getFacadeRoot();
$username = $user->getFirstAttribute($resolver->getLdapDiscoveryAttribute());
return [
$resolver->getEloquentUsernameAttribute() => strtolower($username),
];
}
}
Hi @stevebauman,
Thanks for the reply and help! This is works now! :)
And I have another question of Single Sign On (SSO) Middleware, Assume that I have two Laravel projects A and B, and I want to use project A as SSO server, If the users want to access project B, they must to login from project A first, otherwise, will redirect to project A login view.
My question is : is it possible to post something from project A to project B, to tell project B the user is login or not?
I'm already add WindowsAuthenticate in app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
Middleware\VerifyCsrfToken::class,
\Adldap\Laravel\Middleware\WindowsAuthenticate::class, // Inserted here.
],
];
Thank you very much!
Description:
The first login is successful, but after I logout and re-login, the error message will show as below:
Illuminate\Database\QueryException with message 'SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "users_username_unique" DETAIL: Key (username)=(xxxxx) already exists.
its seem to re-insert data again.
Use php artisan tinker var_dump(Auth::attempt(['username' => 'xxxxx','password' => 'xxxxxx'])); Will show up the same error message.
Steps To Reproduce:
Modified database/migrations/2014_10_12_000000_create_users_table.php // From: $table->string('email')->unique();
// To: $table->string('username')->unique();
Modify the config/adldap.php and config/adldap_auth.php files
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Adldap\Laravel\Facades\Adldap;
use App\User;
}