Don*_*aJo 5 redirect laravel laravel-5 laravel-socialite
这里还有另一个新问题,但希望有人能阐明一些观点:
我将Laravel 5与Socialite结合使用,我希望能够在用户登录后将其重定向到网站上的页面。问题是使用
return redirect('any-path-I-put-here');
Run Code Online (Sandbox Code Playgroud)
只需将其重定向回“ social-site / login?code = afkjadfkjdslkfjdlkfj ...”(其中“ social-site”是指正在使用的任何网站,例如,facebook,twitter,google等)。
因此,在我看来正在发生的事情是,Socialite / Contracts / Provider接口中的redirect()函数覆盖了我事后尝试执行的任何重定向。
为了澄清起见,我的路线设置正确。我已经尝试了可以想象到的每个版本的“重定向”(“到”,“后退”,“预期”,重定向::等),并且正在从我的Auth Controller调用该方法(尽管我已经在其他地方尝试过了)以及)。
问题是,使用社交名流存储和登录用户后,如何覆盖该redirect()?任何帮助表示赞赏!先感谢您。
包含相关重定向的代码为:
public function socialRedirect( $route, $status, $greeting, $user )
{
$this->auth->login( $user, true );
if( $status == 'new_user' ) {
// This is a new member. Make sure they see the welcome modal on redirect
\Session::flash( 'new_registration', true );
return redirect()->to( $route );// This is just the most recent attempt. It originated with return redirect($route);, and has been attempted every other way you can imagine as well (as mentioned above). Hardcoding (i.e., 'home') returns the exact same result. The socialite redirect always overrides anything that is put here.
}
else {
return redirect()->to( $route )->with( [ 'greeting' => $greeting ] );
}
}
Run Code Online (Sandbox Code Playgroud)
...在此之前运行的SocialAuth类大约有500行,因为它必须确定用户是否存在,必要时注册新用户,显示适用于不同场景的表单等。同时,这里的功能是通过Social Auth类发送信息:
private function socialLogin( $socialUser, $goto, $provider, $status, $controller )
{
if( is_null( $goto ) ) {
$goto = 'backlot/' . $socialUser->profile->custom_url;
}
if( $status == 'new_user' ) {
return $controller->socialRedirect($goto, $status, null, $socialUser);
}
else {
// This is an existing member. Show them the welcome back status message.
$message = 'You have successfully logged in with your ' .
ucfirst( $provider ) . ' credentials.';
$greeting =
flash()->success( 'Welcome back, ' . $socialUser->username . '. ' . $message );
return $controller->socialRedirect($goto, $status, $greeting, $socialUser);
}
}
Run Code Online (Sandbox Code Playgroud)
我相信你想多了。使用 Socialite 非常简单:
设置config/services.php。对于脸书我有这个:
'facebook' => [
'client_id' => 'your_fb_id',
'client_secret' => 'your_fb_secret',
'redirect' => '>ABSOLUTE< url to redirect after login', //like: 'http://stuff'
],
Run Code Online (Sandbox Code Playgroud)
然后设置两条路由,一条用于登录,一条用于回调(登录后)。
在登录控制器方法中:
return \Socialize::with('facebook')->redirect();
Run Code Online (Sandbox Code Playgroud)
然后在回调函数中
$fb_user = \Socialize::with('facebook')->user();
// check if user exists, create it and whatnot
//dd($fb_user);
return redirect()->route('some.route');
Run Code Online (Sandbox Code Playgroud)
对于所有其他提供商来说,它应该非常相似。
| 归档时间: |
|
| 查看次数: |
6179 次 |
| 最近记录: |