Add inputs in $request in Laravel auth login() method

  authentication, laravel, php, request

I’m trying to create user authentication for Active Directory. I am using Laravel and standard authentication. I slightly altered the standard login form, earlier there were input fields email and password. In form I changed these two fields:

<input type="text" name="accountName" required> (Active Directory account)

<input type="password" name="activeDirectoryPassword" required> (Active Directory password)

In these fields, users will enter their data from Active Directory.

Further logic looks like this – if the user entered the correct data, I create it in the site database (mysql) and authenticate it. If it has already been created, then I simply authenticate it.

For authentication, I want to add two fields to $request in the $login() method, since Laravel does email and password authentication. ()


namespace IlluminateFoundationAuth;

use IlluminateHttpJsonResponse;
use IlluminateHttpRequest;
use IlluminateSupportFacadesAuth;
use IlluminateValidationValidationException;

trait AuthenticatesUsers
{
    use RedirectsUsers, ThrottlesLogins;

    public function showLoginForm()
    {
        return view('auth.login');
    }

    public function login(Request $request)
    {
        $this->ad($request);
        
        $request['email'] = $newUser->email;
        $request['password'] = $newUser->password;


        $this->validateLogin($request);
        ......
        ......

In $this->ad($request); the logic of connecting to Active Derectory and creating a new user in mysql is written.

In fact, I want to inject into request and add standart fields (email and password) there, by which the user will be authenticated. But it doesn’t work.

I think some form protection is working. Tried deleting @csrf but Laravel throws error.

Source: Laravel

Leave a Reply