简体   繁体   English

laravel facebook如果应用已允许,则不重定向回

[英]laravel facebook no redirect back if app allowed already

I made the auth with socialite/facebook. 我使用社交名流/ facebook进行了身份验证。

My code -- 我的代码-

config/services.php: 配置/ services.php:

'facebook' => [
    'client_id' => 'client_id',
    'client_secret' => 'client_secret',
    'redirect' => 'http://www.example.com/facebook/callback',
],

routes.php: routes.php文件:

Route::get('facebook', 'FacebookController@redirectToProvider');
Route::get('facebook/callback', 'FacebookController@handleProviderCallback');

FacebookController.php: FacebookController.php:

public function redirectToProvider()
{
    return Socialite::with('facebook')->redirect();
}

public function handleProviderCallback(Request $request, User $user)
{
    $users = Socialite::with('facebook')->user();

    // user registration and login
    // if the user is in the database, just login

    return redirect()->back();   
}

Everything works fine, the registration, the login and the redirect until one point. 一切正常,注册,登录和重定向直到一分。

If the app is already allowed, it redirects back normally. 如果该应用程序已被允许,它将正常重定向回原先。 If you first authenticate with Facebook and allow the app, it does not redirect. 如果您先通过Facebook进行身份验证并允许该应用,则该应用不会重定向。

However, if the redirect is the homepage: 但是,如果重定向是主页:

 return redirect('/');

then it works too. 然后它也起作用。

So i found the solution here: http://laravel.io/forum/08-03-2014-redirect-to-the-second-last-page 所以我在这里找到了解决方案: http : //laravel.io/forum/08-03-2014-redirect-to-the-second-last-page

My solved code: 我解决的代码:

public function redirectToProvider()
{
    // added this
    Session::flash('url',$_SERVER['HTTP_REFERER']);

    return Socialite::with('facebook')->redirect();
}

public function handleProviderCallback(Request $request, User $user)
{
    $users = Socialite::with('facebook')->user();

    // user registration and login
    // if the user is in the database, just login

    // redirect changed from redirect()->back(); to this
    return Redirect::to(Session::get('url'));
}

Choose Your App in https://developers.facebook.com and go through the App Review option available in the dashboard and make your app public and full fill the Approval criteria https://developers.facebook.com选择您的应用程序,然后通过信息中心中可用的“ App Review选项,使您的应用程序公开并完全满足批准条件

My main point is that you have everything ok in your side just make some small changes on developer dashboard in the facebook app. 我的主要观点是,您一切正常,只需在Facebook应用程序的开发人员仪表板上进行一些小的更改即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM