Laravel 5.1-通过Socialite的Facebook(客户端错误:400) [英] Laravel 5.1 - Facebook through Socialite (Client Error: 400)
问题描述
使用有关Laracast的本教程(Laravel 5.0 -社交名流),特别是在 min 12.11 之前,我已经成功设置了所有内容.但是,我正在使用Laravel 5.1
Using this tutorial on Laracast (Laravel 5.0 - Socialite), specifically until min 12.11, I have successfully setup everything. However, I am using Laravel 5.1
-
定义了我的路线,但当前已注释掉回调提供程序,因为我只是想通过已获取的令牌获取用户详细信息:
Defined my route but currently commented out the callback provider, as I am just trying to fetch the user details through taken token:
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
//Route::get('auth/facebook/aaa', 'Auth\AuthController@handleProviderCallback');
在config>services.php
中添加了必需品:
Added necessities in config>services.php
:
'facebook' => [
'client_id' => '##',
'client_secret' => env('FB_SECRET_ID'),
'redirect' => 'http://laratest.dev/auth/facebook',
],
我决定暂时返回同一页面(auth/facebook
).这就是为什么我将返回值设置为domain.devv/auth/facebook
进行测试的原因.
I decided to return to the same page (auth/facebook
) for now. That's why I have set the return as domain.devv/auth/facebook
for testing.
-
在我的
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...
Now, I am clicking Login with Facebook
link and getting directed to domain.dev/auth/facebook?code=943299043290...
当我仅使用*First dd
(所有其他注释行都被注释)时,它将返回false
.
When I use only the *First dd
(with all the other commented lines are commented)- it returns false
.
当我仅使用*Second dd
(在注释$user = $this->socialite->driver('facebook')->user();
行时)时,它将返回true
.
When I use the only the *Second dd
(with commenting the line $user = $this->socialite->driver('facebook')->user();
), it returns true
.
因此,一切正常,并通过execute()
,然后通过getAuthorizationFirst()
.最后,返回带有链接(domain.dev/auth/facebook?code=943299043290...
)中包含的已获取令牌的execute()
.
So everything is working perfect and goes through execute()
, then through getAuthorizationFirst()
. Finally, returns back to execute()
with the taken token which is also contained in the link (domain.dev/auth/facebook?code=943299043290...
).
我的问题出现在这里:
第二次我取消注释$user = $this->socialite->driver('facebook')->user();
时,出现错误:
At the second I am uncommenting $user = $this->socialite->driver('facebook')->user();
, I am getting an error:
Middleware.php第69行中的ClientException:客户端错误:400
ClientException in Middleware.php line 69: Client error: 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()中
this line ($user = $this->socialite->driver('facebook')->user();
) is not working for me for some reasons (while it does in the tutorial (min 12.11 for 15-second brief explanation).
每当我使用$user = $this->socialite->driver('facebook')->user();
时,都会收到错误 ClientException in Middleware.php line 69: Client error: 400
,当然,我也收不到dd($user)
.
Whenever I use $user = $this->socialite->driver('facebook')->user();
, I receive the error ClientException in Middleware.php line 69: Client error: 400
and, of course, I can't get dd($user)
.
要添加的内容是,当我看到ClientException错误时,链接仍带有以下代码:(domain.dev/auth/facebook?code=943299043290...
)
To add, when I see the ClientException error, the link is still with the code: (domain.dev/auth/facebook?code=943299043290...
)
推荐答案
我也遇到了这个问题,就我而言,我必须将我的域添加到config/session.php的domain字段中,并将其也添加到我的应用中提供者
i was having this issue too, in my case i have to add my domain in config/session.php in the domain field and add it too in my app provider
这篇关于Laravel 5.1-通过Socialite的Facebook(客户端错误:400)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!