我设法使连接工作到AD,但我似乎无法使Auth :: attemnt工作。 它总是会返回false。有人有想法或暗示吗?
public function login(Request $request) {
$search = Adldap::search()->where('samaccountname', '=', 'tba')->get();
// this is returning the correct user
dd($search);
//'username' => 'tba'
// 'passwrod' => 'is the entered password'
//this goes into error part
if (Auth::attempt(request()->only('username', 'password'))) {
dd('success');
} else {
dd('error');
}
}
'usernames'=> [
/*
|--------------------------------------------------------------------------
| LDAP
|--------------------------------------------------------------------------
|
| This is the LDAP users attribute that you use to authenticate
| against your LDAP server. This is usually the users
|'sAMAccountName' / 'userprincipalname' attribute.
|
| If you'd like to use their username to login instead, insert `samaccountname`.
|
*/
'ldap' => 'samaccountname',
/*
|--------------------------------------------------------------------------
| Eloquent
|--------------------------------------------------------------------------
|
| This is the attribute that is used for locating
| and storing the LDAP username above.
|
| If you're using a `username` field instead, change this to `username`.
|
| This option is only applicable to the DatabaseUserProvider.
|
*/
'eloquent' => 'username',
啊对,
Adldap :: auth() - >尝试(仅限于request() - >('username','password'))
给我一个ErrorException: 缺少Adldap \ Auth \ Guard :: attempt()的参数2,在第63行的/media/sf_www/prm/app/Http/Controllers/Auth/LoginController.php中调用并定义<
更新:
我设法取得了成功:
if (Adldap::auth()->attempt(request()->get('username'), request()->get('password'))) {
dd('success');
} else {
dd('error');
}
我可以获得成功,奇怪的是我必须使用CN名称作为用户名。 如果我使用samaccountname,它是“tba”它不起作用。
更有趣的是,Auth根本不工作。返回False
Auth::attempt(request()->only('username', 'password'))
我可能需要一些帮助/介绍。
答案 0 :(得分:1)
我认为这很简单。该函数需要2个参数,您将其传递给一个参数。快速查看文档显示第一个参数是用户名,第二个参数是密码。在执行array
时,您会收到Auth::attempt(request()-get('username'), request()->get('password'))
。
取而代之的是{{1}}