Closed chaos520 closed 5 years ago
I finally found out that the ldap user for admin needed to be with a domain name...
'username' => env('LDAP_USERNAME', 'ldapauth@test.local'),
otherwise it will throw something like
80090308: LdapErr: DSID-0C090400, comment: AcceptSecurityContext error, data 52e, v1db1
I found this by dumping in the \Adldap\Auth\Guard::bind
catch ....
dd($username, $password,$this->connection->getDetailedError(), $e->getMessage(), $e->getCode(), $e->getFile(), $e->getLine());exit;
Hi @chaos520,
@Artistan is correct, you can only use users full distinguished names or user principal names to authenticate with ActiveDirectory. Here's an example of each:
Distinguished Name:
cn=John Doe,ou=Users,dc=acme,dc=org
User Principal Name
jdoe@acme.org
From first glance, you're doing a ton of custom auth work in the LoginController
. You don't need to do this using the Adldap2-Laravel auth driver.
You are also missing the username
input field from your login.blade.php
view - it's currently using an email
input field.
Please follow the quick start here:
https://adldap2.github.io/Adldap2-Laravel/#/auth/introduction?id=quick-start-from-scratch
Hi @stevebauman
As I recreate the project again, seems still couldn't get it.
ldap_auth.php
<?php
return [
'connection' => env('LDAP_CONNECTION', 'default'),
'provider' => Adldap\Laravel\Auth\DatabaseUserProvider::class,
'model' => App\User::class,
'rules' => [
Adldap\Laravel\Validation\Rules\DenyTrashed::class,
],
'scopes' => [
],
'identifiers' => [
'ldap' => [
'locate_users_by' => 'userprincipalname',
'bind_users_by' => 'distinguishedname',
],
'database' => [
'guid_column' => 'objectguid',
'username_column' => 'email',
],
'windows' => [
'locate_users_by' => 'samaccountname',
'server_key' => 'AUTH_USER',
],
],
'passwords' => [
'sync' => env('LDAP_PASSWORD_SYNC', false),
'column' => 'password',
],
'login_fallback' => env('LDAP_LOGIN_FALLBACK', false),
'sync_attributes' => [
'email' => 'userprincipalname',
'name' => 'cn',
],
'logging' => [
'enabled' => env('LDAP_LOGGING', true),
'events' => [
\Adldap\Laravel\Events\Importing::class => \Adldap\Laravel\Listeners\LogImport::class,
\Adldap\Laravel\Events\Synchronized::class => \Adldap\Laravel\Listeners\LogSynchronized::class,
\Adldap\Laravel\Events\Synchronizing::class => \Adldap\Laravel\Listeners\LogSynchronizing::class,
\Adldap\Laravel\Events\Authenticated::class => \Adldap\Laravel\Listeners\LogAuthenticated::class,
\Adldap\Laravel\Events\Authenticating::class => \Adldap\Laravel\Listeners\LogAuthentication::class,
\Adldap\Laravel\Events\AuthenticationFailed::class => \Adldap\Laravel\Listeners\LogAuthenticationFailure::class,
\Adldap\Laravel\Events\AuthenticationRejected::class => \Adldap\Laravel\Listeners\LogAuthenticationRejection::class,
\Adldap\Laravel\Events\AuthenticationSuccessful::class => \Adldap\Laravel\Listeners\LogAuthenticationSuccess::class,
\Adldap\Laravel\Events\DiscoveredWithCredentials::class => \Adldap\Laravel\Listeners\LogDiscovery::class,
\Adldap\Laravel\Events\AuthenticatedWithWindows::class => \Adldap\Laravel\Listeners\LogWindowsAuth::class,
\Adldap\Laravel\Events\AuthenticatedModelTrashed::class => \Adldap\Laravel\Listeners\LogTrashedModel::class,
],
],
];
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';
}
}
User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'username', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
login.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
@csrf
<!-- <div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div> -->
<div class="form-group row">
<label for="username" class="col-md-4 col-form-label text-md-right">{{ __('Username') }}</label>
<div class="col-md-6">
<input id="username" type="username" class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}" name="username" value="{{ old('username') }}" required autofocus>
@if ($errors->has('username'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('username') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
@if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
@if (Route::has('password.request'))
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
@endif
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
It throws this exception after I try to login via UI with userprincipalname and password RuntimeException The 'email' key is missing from the given credentials array.
As I tested command php artisan adldap:import, it does return my Active Directory user list so I would assume that my ldap.php settings is correct, just left the ldap_auth.php settings need to be fine tuned.
[2019-04-09 10:43:39] local.INFO: User 'Domain displayName' is being imported.
[2019-04-09 10:43:39] local.INFO: User 'Domain displayName' is being synchronized.
[2019-04-09 10:43:39] local.INFO: User 'Domain displayName' has been successfully synchronized.
[2019-04-09 10:43:39] local.ERROR: Unable to import user Domain displayName. SQLSTATE[HY000]: General error: 1364 Field 'username' doesn't have a default value (SQL: insert into users
(objectguid
, email
, name
, password
, updated_at
, created_at
)
but it does not allow me to import to db as well.
Hi @chaos520 ,
I have a exact problem as your, did by any chance you already fix this?
@jee-soon Yes, end up I have sorted the issues by myself.
You may post your config then I can help you to check on it.
@chaos520 i also sorted it out. Thanks!
I have a same problem
[2019-08-28 15:00:17] local.INFO: LDAP (ldap://181.xxx.xxx.xxx:389) - Connection: default - Operation: Binding - Username:
[2019-08-28 15:00:17] local.INFO: LDAP (ldap://181.xxx.xxx.xxx:389) - Connection: default - Operation: Bound - Username:
[2019-08-28 15:00:17] local.INFO: LDAP (ldap://181.xxx.xxx.xxx:389) - Connection: default - Operation: Search - Base DN: dc=corp,dc=xxx,dc=com,DC=bo - Filter: (&(objectclass=user)(objectcategory=person)(!(objectclass=contact))(samaccountname=labautistab)) - Selected: (*,objectguid) - Time Elapsed: 28.29
Any idea? Could you show me your settings including the .env?
Thanks.
I have the same problem @luisbauti92 did you solve it?
@chaos520 @jee-soon can you share how you sorted out the problem? that would help the community to solve the problem as well.
Thanks!
@pleone I solved it by placing the suffix directly in the LDAP_USERNAME=user@corp.com
I hope it helps you
@joseasanchezzz91 did you solve it just with that? user@corp.com, what is user parameter?
@luisbauti92 I resolved with this LDAP configuration
in the ldap_auth file change to this 'ldap' => [
'locate_users_by' => 'mail',
'bind_users_by' => 'distinguishedname',
], change to mail because placing the suffix to the username already connected to the LDAP but did not authenticate it then reading the log change the match variable
@luisbauti92 I resolved with this LDAP configuration
LDAP_HOSTS=xx.x.x.xxx
LDAP_PORT=xxx
LDAP_BASE_DN="dc=corp,dc=xxx,dc=com"
LDAP_USERNAME=usuario( with this config it doesn't work for me)
LDAP_USERNAME=usuario@corp.com (this is the user that has permission in the LDAP )
LDAP_PASSWORD=xxxxxxx
in the ldap_auth file change to this 'ldap' => [
'locate_users_by' => 'mail', 'bind_users_by' => 'distinguishedname', ],
change to mail because placing the suffix to the username already connected to the LDAP but did not authenticate it then reading the log change the match variable
can you speak spanish? usuario jeje. Thanks, I will try it.
Description:
Hi, Admin I had tried the tutorial by referring https://github.com/jotaelesalinas/laravel-simple-ldap-auth
Open LDAP authentication is success without any issues, however for Active Directory authentication, it does not return any error message and redirected to Login page.
Therefore I posted here to seek for advice.
Please refer the code below.
Steps To Reproduce:
.env
ldap.php
for the LDAP_USERNAME, what should I use? samAccountName@Domain.com or Domain\samAccountName or samAccountName only?
ldap.auth.php
LoginController.php
Migration Files
Login.blade.php