php - 如何在 Laravel 5.7 中使用第三方 api 实现后备身份验证检查?
问题描述
您好,感谢所有花时间查看此内容的人。
这里有一点背景。我们当前的系统有一个包含一组用户的客户端仪表板。登录此仪表板时,它将首先查看用户名是否在数据库中。如果找不到,它会调用具有“网站管理员”管理员列表的第三方 api 并在那里验证凭据。
我正在尝试在 Laravel 5.7 中实现此功能,但我不确定如何去做。到目前为止,我已经创建了一个调用 API 以验证凭据的 ActiveDirectory 类。然后在LoginController
我有以下块:
public function login(Request $request)
{
// Validate the form data
$this->validate($request, [
$this->username() => 'required',
'password' => 'required|min:6'
]);
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// Need to check if user is in active directory
if (ActiveDirectory::validateWebmasterAdmin(request('username'), request('password'))) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
我得到了正确的响应,但用户仍未通过身份验证,我确信这是由于我没有正确执行某些操作。我认为这与$this->sendLoginResponse($request)
.
如果我从 API 中获得匹配的凭据,我想使用我在应用程序中返回的一些数据。例如,API 会返回一个名称,我想在这样的视图中使用它 {{ Auth::user()->name }}
任何帮助将不胜感激。
解决方案
推荐阅读
- r - 随机的,默认的,函数在 R 中不起作用(昨天的 freq_terms(),今天的 tokens())
- android - 如何在 Flutter 中的 Column 上的 Widget 之间添加垂直分隔线?
- perl - 将输出加载到文件/perl
- javascript - 使用这个访问 Vue 实例
- mysql - 获取与列表(数组)中精确值匹配的记录
- javascript - 在 JSON 中绑定没有“值”的选项
- java - java.util.NoSuchElementException 错误(可能是因为 Scanner)
- vb.net - 保存数据以访问不起作用,尽管没有错误
- encryption - oiosaml 密钥库中是否可以有多个密钥?
- python - Kafka Python,如何跟踪在不同进程中开始的消费者