Laravel 5.2认证不发送cookie
问题描述:
td; dr:我向认证请求发送JSON响应,但会话cookie丢失。Laravel 5.2认证不发送cookie
我使用的登录方法与Illuminate\Foundation\Auth\AuthenticatesUsers
类似。在我的情况下,呈现它以JSON格式发送并且没有视图的响应。这里是控制器代码:
class DashboardController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $guard = 'web';
public function login(LoginRequest $request)
{
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $lockedOut = $this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
$credentials = $this->getCredentials($request);
if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
Auth::user()->incrementLoginCounter();
return $this->handleUserWasAuthenticated($request, $throttles);
}
if ($throttles && ! $lockedOut) {
$this->incrementLoginAttempts($request);
}
return $this->sendFailedLoginResponse($request);
}
}
它与Laravel的特质基本相同。
问题:没有发送响应的cookie。
这里是我知道的:
- 用户表的数据库中的remember_token列得到正确设置
- 我可以
response()-> ... ->cookie('name', 'value')
- 手动设置cookie手动设置的饼干正确发送回应
- 警卫驱动程序设置为
session
,提供程序设置为App\User
类 - 会话驱动程序是
file
并且config是默认的laravel config - Web中间件与默认相同,Csrf-Middleware在该端点上关闭。
我希望什么:最好的情况 - 对于这个问题,或者有什么我可以测试弄清楚为什么它不工作任何的窍门和创意的解决方案。
答
我自己发现了我的问题的解决方案,这是一个相当奇怪的事情。我所做的就是在github上打开laravel存储库,然后浏览将在请求中加载的所有应用程序文件,并将它们与我的本地版本进行比较。这意味着路由器,控制器,中间件,提供商等。
RouteServiceProvider缺少整个方法。这导致该应用程序告诉我,该网页中间件实际上没有应用。
也许这是因为以前的开发人员更新Laravel到最新版本,并没有做正确的工作。也许这是一些Git合并,搞砸了。
重点是 - 有时它很好,只是逐行浏览所有文件并将其与工作版本进行比较:)