使用弹出式身份验证重定向问题

时间:2017-12-12 21:17:44

标签: javascript laravel vue.js laravel-socialite

我遇到的问题是,当我尝试点击通过Facebook登录按钮时,会显示一个弹出窗口,它会进行身份验证,302请求会发送到我的服务器,然后发送的请求会抛出错误:

Failed to load https://www.facebook.com/v2.10/dialog/oauth?client_id=1869475260039930&redirect_uri=https%3A%2F%2Fordering.dev%2Fapi%2Flogin%2Ffacebook%2Fcallback&scope=email&response_type=code&display=popup: Response for preflight is invalid (redirect)

Route::post('login/{provider}', 'SocialAuthController@redirectToProvider');
Route::get('login/{provider}/callback', 'SocialAuthController@handleProviderCallback')->name('api-callback');

我的控制器:

public function redirectToProvider($provider)
{
    // will get called
    return Socialite::driver($provider)->stateless()->asPopup()->redirect();
}

public function handleProviderCallback($provider)
{
    // this endpoint is never called
    return response()->json('test');

    // more logic
}

前端代码:

socialLogin(provider) {
    console.log('social login');
    let this_ = this;
    // vue-authenticate
    this.$auth.authenticate(provider).then(function () {
       // success - never called
    }).catch(function (err) {
        // error is always thrown
        console.log('error is', err);
    });
}

如何确保调用我的handleProviderCallback($provider)函数并传递正确的信息?

0 个答案:

没有答案