How can I implement a fallback authentication check with a third party api in Laravel 5.7?
Hello and thanks to all who take the time to look this over.
Here is a little background. Our current system has a client dashboard that contains a set of users. When logging into this dashboard, it will first see if the username is in the database. If it doesn't find one then it calls a third party api that has a list of "webmaster" admins and validates credentials there.
I am trying to implement this functionality in Laravel 5.7 and I am not sure how to go about doing it. So far I have created an ActiveDirectory class that calls out to the API to validate the credentials. Then in the LoginController I have the following block:
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);
}
I am getting the right responses back, but the user is still not being authenticated which I am sure is due to something I am not doing correctly. I presume it has something to do with the $this->sendLoginResponse($request).
If I get a match on the credentials from the API, I would like to use some of the data I get back in the application. For example the API would return a name, and I would like to use it in the views like this {{ Auth::user()->name }}
Any help would be greatly appreciated.
Please or to participate in this conversation.