Reputation: 428
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?
Upvotes: 3
Views: 757
Reputation: 422
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.
Upvotes: 2