我是Laravel Socialite的新手,我在从社交媒体登录重定向时遇到此错误
/ vendor / laravel / socialite / src / Two / AbstractProvider.php中的Laravel \ Socialite \ Two \ InvalidStateException:209 **
即使我尝试过此解决方案https://stackoverflow.com/a/31738836/4428431但我仍面临同样的错误。
这里是社交网络控制器的代码
// Redirect to Social provider for login
public function redirectToProvider($provider)
{
return Socialite::driver($provider)->redirect();
}
// Handling get request from social provider
public function handleProviderCallback($provider, Request $request)
{
$user = Socialite::driver($provider)->user();
}
实际上代码在开始时工作但在我将非www重定向到www后它停止了工作。 这里是.htaccess文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L]
RewriteRule .* index.php?/$0 [PT,L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#RewriteCond %{HTTPS} !on
#RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
答案 0 :(得分:1)
我也遇到了同样的问题,并通过添加->stateless()
$user = Socialite::driver( $provider )->stateless()->user();
答案 1 :(得分:0)
使用会话保护或无状态
1.会话守卫
你可以在 config/auth.php (drivers and providers) 中看到guard
Route::group(['middleware' => ['web']], function () {
Route::get('login/{provider}', 'SocialController@redirect');
Route::get('login/{provider}/callback','SocialController@Callback');
Route::get('login/{provider}/callback','SocialController@Callback');
});
这里是网络守卫
2.stateless 使用 (->stateless)
$user = Socialite::driver( $provider )->stateless()->user();
注意: 无状态身份验证不适用于 Twitter 驱动程序,它使用 OAuth 1.0 进行身份验证。