【发布时间】:2015-10-14 02:09:35
【问题描述】:
使用this tutorial on Laracast (Laravel 5.0 - Socialite),特别是直到 min 12.11,我已经成功设置了一切。但是,我使用的是 Laravel 5.1
-
定义了我的路由,但当前注释掉了回调提供者,因为我只是试图通过获取的令牌获取用户详细信息:
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider'); //Route::get('auth/facebook/aaa', 'Auth\AuthController@handleProviderCallback'); -
在
config>services.php中添加了必需品:'facebook' => [ 'client_id' => '##', 'client_secret' => env('FB_SECRET_ID'), 'redirect' => 'http://laratest.dev/auth/facebook', ],
我决定暂时返回同一页面 (auth/facebook)。这就是为什么我将返回设置为domain.devv/auth/facebook 进行测试。
-
在我的
AuthController.php,我设置:public function redirectToProvider(AuthenticateUser $authenticateUser, Request $request) { return $authenticateUser->execute($request->has('code')); } -
最后,在我的
AuthenticateUser.php:use Illuminate\Contracts\Auth\Guard; (PS. I changed Authenticator to Guard) class AuthenticateUser { private $users; private $socialite; private $auth; public function __construct(UserRepository $users, Socialite $socialite, Guard $auth) { $this->users = $users; $this->socialite = $socialite; $this->auth = $auth; } public function execute($hasCode) { // dd($hasCode) *First dd if ( ! $hasCode) return $this->getAuthorizationFirst(); // $user = $this->socialite->driver('facebook')->user(); // dd($hasCode) *Second dd // dd($user) *Third dd } private function getAuthorizationFirst() { return $this->socialite->driver('facebook') ->scopes(['public_profile', 'email'])->redirect(); } }
现在,我点击Login with Facebook 链接并被定向到domain.dev/auth/facebook?code=943299043290...
当我只使用*First dd(所有其他注释行都被注释)时,它返回false。
当我只使用*Second dd(注释$user = $this->socialite->driver('facebook')->user(); 行)时,它返回true。
所以一切都很完美,通过execute(),然后通过getAuthorizationFirst()。最后,返回 execute() 并使用链接中包含的令牌 (domain.dev/auth/facebook?code=943299043290...)。
我的问题出现在这里:
在我取消注释 $user = $this->socialite->driver('facebook')->user(); 时,我收到一个错误:
Middleware.php 第 69 行中的ClientException:客户端错误:400
1.在 /Applications/MAMP/htdocs/laratest/vendor/guzzlehttp/guzzle/src/Middleware.php 第 69 行
2.在 Promise.php 第 199 行中的 Middleware::GuzzleHttp{closure}(object(Response))
3.在 Promise.php 第 152 行中的 Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null))
4.在 TaskQueue.php 第 60 行的 Promise::GuzzleHttp\Promise{closure}() 处
5.在 CurlMultiHandler.php 第 96 行中的 TaskQueue->run()
由于某些原因,这条线 ($user = $this->socialite->driver('facebook')->user();) 对我来说不起作用(而在 tutorial 中它确实起作用(12.11 分钟,15 秒的简要说明 )。
每当我使用$user = $this->socialite->driver('facebook')->user(); 时,我都会收到错误ClientException in Middleware.php line 69: Client error: 400,当然,我无法获得dd($user)。
补充一点,当我看到ClientException错误时,链接仍然带有代码:(domain.dev/auth/facebook?code=943299043290...)
【问题讨论】:
标签: php facebook-graph-api laravel laravel-5.1 laravel-socialite