My page in the application is embeded in another application. To get to the embeded page username and password are passed using the URL like &user=foo&password=bar
. The route to this page goes through a middleware('loginViaApp')
. I want this middleware to login using the parameters, but i don't know how to login this way. I would expect something like this, but i don't know how to login using middleware.
class LoginViaApp:
{
if(Auth::login(['username'=>'foo','password'=>'bar'])){
return $next($request);
}else{
return error('403');
}
}
Can somebody please help me figure out how to login using middleware with parameters in the url?
Kind regards, Jeff
CodePudding user response:
You can use this logic for that, just modify it according to your need and use it in middleware
$user = User::where('username',$username)->first();
if(null === $user ){
return redirect()->route('login');
}
$passwordPass = Hash::check($password, $user->password);
if($passwordPass){
auth()->loginUsingId($user->id);
return $next($request);
}
return;