首页 > 解决方案 > 如何在 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 }}

任何帮助将不胜感激。

标签: phplaravelauthenticationlaravel-5laravel-5.7

解决方案


推荐阅读