3

I want to change the password field to user_password in the SQL request when I use the connection HTTP Basic Authentication. The middleware that I use is auth.basic specific to Laravel. I managed to change the username by creating middleware, but I can't change the password field.

class CustomBasicAuth extends AuthenticateWithBasicAuth
{
    public function handle($request, Closure $next, $guard = null, $field = null)
    {
        $this->auth->guard($guard)->basic($field ?: 'user_username');

        return $next($request);
    }
}

I did some research, and I saw that we have to try and modify this method.

/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php

class SessionGuard implements StatefulGuard, SupportsBasicAuth
{
    use GuardHelpers, Macroable;

    protected function basicCredentials(Request $request, $field)
    {
        return [$field => $request->getUser(), 'password' => $request->getPassword()];
    }
}

Does anyone know how to change it without modifying the base file?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
diego
  • 408
  • 8
  • 21
  • 2
    You can customize external package classes just by extending them and overriding the methods you need to be changed. It may require extending multiple classes in order to change the base class calls to your custom one. – vvmul Apr 12 '19 at 02:51
  • Thanks, you helped me solve it. – diego Apr 12 '19 at 07:19
  • Ok, will post it as an answer then in case anyone else faces the same problem :) – vvmul Apr 12 '19 at 07:37

1 Answers1

2

You can customize external package classes just by extending them and overriding the methods you need to be changed. It may require extending multiple classes in order to change the places where the base class is called to your custom one.

vvmul
  • 402
  • 4
  • 13
  • more precisely I created an `SessionGuardExtended` class that extends `SessionGuard` then I added in `AppServiceProvider` – diego Apr 12 '19 at 07:50