Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用户授权出现The key "access_token" could not be empty #527

Closed
iScript opened this issue Nov 22, 2016 · 6 comments
Closed

用户授权出现The key "access_token" could not be empty #527

iScript opened this issue Nov 22, 2016 · 6 comments

Comments

@iScript
Copy link

iScript commented Nov 22, 2016

我用的环境

PHP 版本:7
overtrue/wechat 版本:3.1

问题及现象

[2016-11-22 00:00:32] local.ERROR: InvalidArgumentException: The key "access_token" could not be empty. in /home/www/wt-game/vendor/overtrue/socialite/src/AccessToken.php:33

平常测试基本没出现,都能正常运行。但每天看laravel的错误日志都有几千条这样的错误日志。
都是同一个方法里的, 以下是详细错误日志:

[2016-11-22 00:25:31] local.ERROR: InvalidArgumentException: The key "access_token" could not be empty. in /home/www/wt-game/vendor/overtrue/socialite/src/AccessToken.php:33
Stack trace:
#0 /home/www/wt-game/vendor/overtrue/socialite/src/Providers/WeChatProvider.php(163): Overtrue\Socialite\AccessToken->__construct(Array)
#1 /home/www/wt-game/vendor/overtrue/socialite/src/Providers/WeChatProvider.php(155): Overtrue\Socialite\Providers\WeChatProvider->parseAccessToken('{"errcode":4002...')
#2 /home/www/wt-game/vendor/overtrue/socialite/src/Providers/AbstractProvider.php(173): Overtrue\Socialite\Providers\WeChatProvider->getAccessToken('001ipbjl0ejsh52...')
#3 /home/www/wt-game/app/Http/Controllers/WechatController.php(35): Overtrue\Socialite\Providers\AbstractProvider->user()
#4 [internal function]: App\Http\Controllers\WechatController->callback()
#5 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#6 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('callback', Array)
#7 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Route.php(189): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\WechatController), 'callback')
#8 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Route.php(144): Illuminate\Routing\Route->runController()
#9 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Router.php(642): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#10 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Router->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#11 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#12 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#14 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#15 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /home/www/wt-game/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))

@Sunappnio
Copy link

我也遇到了这个情况,我用的中间件,应该是用户在授权失败页面刷新导致的。

@overtrue
Copy link
Collaborator

那是错误的使用啊,授权失败就不应该刷新啊,那我也解决不了啊

@iScript
Copy link
Author

iScript commented Nov 27, 2016

应该不是重复刷新导致的。
我在oauth页面Session::put('fo', '1');
在callback页面 判断了,重复刷新会自动跳转到oauth页面。
function callback(){
if(!Session::get('fo')){
return redirect("/wechat/oauth");
}
Session::forget("fo");
}

可还是会出现这错误

@xiaohuilam
Copy link

xiaohuilam commented Nov 28, 2016

我也出现,并非授权失败。

环境:SwooleFramework,PHP 7.09
经过测试,没有调用到overtrue/wechat/src/Core/AccessToken
网络出流量抓包,给微信的请求的access_token没有带

此为bug~

@overtrue
Copy link
Collaborator

@iScript @Sunappnio @xiaohuilam 请更新版本:

$ composer update overtrue/socialite -vvv

@iScript
Copy link
Author

iScript commented Dec 1, 2016

我看了下请求微信的日志,code倒是每次都有带的, 不知道是不是微信有时会2次redirect回来的原因。有什么好的解决办法。。
别人也遇到过。 https://segmentfault.com/q/1010000002739502

@overtrue overtrue closed this as completed Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants