[英]Laravel Socialite Facebook error: “POST https://graph.facebook.com/oauth/access_token resulted in a `400 Bad Request` ”
I've made social login using Laravel Socialite
for facebook and it was working fine. 我使用Laravel Socialite
for facebook进行了社交登录,它运行良好。 I haaven't changed anything and now it's not working. 我没有改变任何东西,现在它没有用。 It shows this error when trying to login: 它在尝试登录时显示此错误:
Client error:
POST https://graph.facebook.com/oauth/access_token resulted in a
400 Bad Request response: {"error":{"message":"This IP can't make requests for that application.","type":"OAuthException","code":5,"fbtrace_id":"D (truncated...)
Client error:
POST https://graph.facebook.com/oauth/access_token resulted in a
400 Bad Request response: {"error":{"message":"This IP can't make requests for that application.","type":"OAuthException","code":5,"fbtrace_id":"D (truncated...)
I haven't changed setting in my facebook app, nor in my code. 我没有更改我的Facebook应用程序中的设置,也没有更改我的代码。 My code is the following: 我的代码如下:
Route::get('login', ['as' =>'getLogin', 'uses'=>'Auth\\AuthController@getLogin']); Route::get('handleProviderCallback/{provider}', 'Auth\\AuthController@handleProviderCallback');
public function login($provider = false) { if(!$provider) { $user = Input::all(); $auth_user = new AuthenticateUser(); $is_logged = $auth_user->findByEmailOrCreate($user, false); if($is_logged) { Session::put('user', Auth::user()); Session::put('user_id', Auth::user()->id); Session::put('email', Auth::user()->email); Session::put('name', Auth::user()->name); return redirect()->intended('dashboard'); } return redirect('/')->withInput()->with('error', 'Wrong username or password!'); } return \\Socialite::with('facebook')->redirect(); } public function handleProviderCallback($provider=false) { if(Input::has('code')) { $user = \\Socialite::with($provider)->user(); $auth_user = new AuthenticateUser(); $provider_user = $auth_user->findByEmailOrCreate($user, $provider); Session::put("user", array($provider_user)); Session::put('user_id', $provider_user->id); Session::put('email',$provider_user->email); Session::put('name',$provider_user->name); return redirect('dashboard'); } }
Problem appears in handleProviderCallback
method in this line: 问题出现在此行的handleProviderCallback
方法中:
$user = \\Socialite::with($provider)->user();
. 。
When I only dump this: $user = \\Socialite::with($provider)
当我只转储这个: $user = \\Socialite::with($provider)
it shows data but when it is used like that to get user data it returns the error: 它显示数据,但是当它被用于获取用户数据时,它会返回错误:
$user = \\Socialite::with($provider)->user();
In config/services.php
I've set settings like this example: 在config/services.php
我设置了如下例子的设置:
'facebook' => [ 'client_id' => 'my-client-id-from-fb-app', 'client_secret' => 'my-secret-code-from-fb-app', 'redirect' => 'http://my-example-domain/my-site/handleProviderCallback/facebook' ],
In my facebook app I've set in settings: 在我的Facebook应用程序中,我设置了以下设置:
App Domains: my-example-domain, Privacy Policy URL: http://my-example-domain/my-site/, Site URL: http://my-example-domain/my-site/handleProviderCallback/facebook, Valid OAuth redirect URIs: http://my-example-domain/my-site/handleProviderCallback/facebook
I had this message on my local machine after getting secret key value from .env file 从.env文件获取密钥值后,我在本地计算机上收到此消息
ClientException in RequestException.php line 111:
enter code here Client error: `POST
https://graph.facebook.com/v2.8/oauth/access_token` resulted in a `400
Bad Request` response:
{"error":{"message":"Error validating client
secret.","type":"OAuthException","code":1,"fbtrace_id":"ID"}}
As expected problem was with secret key, I pasted it wrong, so after double check and right copy/past from fb everything worked. 正如预期的问题是秘密密钥,我粘贴错了,所以经过双重检查和正确复制/从fb过去一切正常。
Hope this info will help somebody. 希望这些信息对某人有所帮助。
Yeah, I didn't check the request at all to see what's returned but someone on Larachat helped me solve this problem. 是的,我根本没有查看请求,看看是什么回来了但是Larachat上的某个人帮助我解决了这个问题。
All I had to do before getting the user and handle the request was to add the following code in the callback method: 在获取用户并处理请求之前我所要做的就是在回调方法中添加以下代码:
if (!$request->has('code') || $request->has('denied')) {
return redirect('/');}
What's your Laravel version? 你的Laravel版本是什么?
I've experienced the exact same problem and after going through the socialite package and make little changes, it solves the problem. 我遇到了完全相同的问题,经过社交名媛包后做了一点改动,就解决了这个问题。 You might want to give it a try. 你可能想尝试一下。
vendor/laravel/socialite/TwoFacebookProvider line 81 vendor / laravel / socialite / TwoFacebookProvider第81行
Replace this 替换它
parse_str($response->getBody(), $data);
with 同
$data = json_decode($response->getBody(), true);
It seems like the data isn't adding 好像数据没有添加
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.