Laravel Socialite Facebook错误:"POST https://graph.facebook.com/oauth/access_token导致出现"400错误请求". [英] Laravel Socialite Facebook error: "POST https://graph.facebook.com/oauth/access_token resulted in a `400 Bad Request` "

查看:137
本文介绍了Laravel Socialite Facebook错误:"POST https://graph.facebook.com/oauth/access_token导致出现"400错误请求".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Laravel Socialite进行了Facebook的社交登录,并且工作正常.我没有做任何更改,但现在不起作用.尝试登录时显示此错误:

I've made social login using Laravel Socialite for facebook and it was working fine. 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错误的请求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_tokenresulted in a400 Bad Requestresponse: {"error":{"message":"This IP can't make requests for that application.","type":"OAuthException","code":5,"fbtrace_id":"D (truncated...)

我没有在我的Facebook应用程序或代码中更改设置. 我的代码如下:

I haven't changed setting in my facebook app, nor in my code. 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');
        }
    }

问题出现在此行的handleProviderCallback方法中

Problem appears in handleProviderCallback method in this line:

$user = \Socialite::with($provider)->user();.

当我仅转储此内容时: $user = \Socialite::with($provider)

When I only dump this: $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();

config/services.php中,我已经设置了以下示例:

In config/services.php I've set settings like this example:

  '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'
    ],

在我的Facebook应用中,我已设置了以下设置:

In my facebook app I've set in settings:

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

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

推荐答案

是的,我根本没有检查请求以查看返回了什么,但是Larachat上的某个人帮助我解决了这个问题.

Yeah, I didn't check the request at all to see what's returned but someone on Larachat helped me solve this problem.

在吸引用户和处理请求之前,我要做的就是在回调方法中添加以下代码:

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('/');}

这篇关于Laravel Socialite Facebook错误:"POST https://graph.facebook.com/oauth/access_token导致出现"400错误请求".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆