我做了从5.2到5.3的Laravel更新,当我把它放在服务器上时出乎意料,会议没有工作......
我已经尝试过做一些事情,但一切都没有用......
网络路线文件
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('auth/facebook', 'SocialAuthController@redirect');
Route::get('auth/facebook/callback', 'SocialAuthController@handleProviderCallback');
身份验证文件
/**
* Obtain the user information from Facebook.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('facebook')->user();
$authUser = $this->findOrCreateUser($user);
$id = $authUser['id'];
$email = $authUser['email'];
$password = $authUser['senha'];
$credentials = array('email' => $email, 'password' => $password, 'excluded' => 0);
Auth::attempt($credentials);
Auth::loginUsingId($id);
如果我运行dd(Auth :: user()); auth正在运行,但重定向后会话丢失
内核文件
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
];
}
答案 0 :(得分:1)
要解决此问题,请更改文件session.php
寻找
'cookie' => 'laravel_session'
并改为
'cookie' => 'app_session',
之后一切正常
答案 1 :(得分:0)
以下答案无效。
当我升级到5.3版本时,我需要移动路径文件,发现我需要删除网络中间件行,这个问题就开始了......
我刚刚重新调整了这条线,它现在正在工作。
Route::group(['middleware' => ['web']], function () {
Route::get('auth/facebook', 'SocialAuthController@redirect');
Route::get('auth/facebook/callback', 'SocialAuthController@handleProviderCallback');