- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用 URL 注册锦标赛:
http://laravel.dev/tournaments/1/register/
这个 URL 在中间件 'auth' 中,所以如果用户没有登录,他将被重定向到登录页面。
我需要的是重定向到
http://laravel.dev/tournaments/1/register/
社交登录后(我有 2 个提供商,fb 和 google)
在这种情况下,我不希望用户被重定向到 .env 中定义的重定向 url
这是我用来登录 Socialite 的函数:
public function execute($request, $listener, $provider) {
if (!$request) {
return $this->getAuthorizationFirst($provider);
}
$user = $this->users->findByUserNameOrCreate($this->getSocialUser($provider), $provider);
if (!is_null($user)){
$this->auth->login($user, true);
}else{
Session::flash('error', Lang::get('auth.account_already_exists'));
return redirect('auth/login');
}
return $listener->userHasLoggedIn($user);
}
我怎样才能使系统将我重定向到初始操作而不是默认的 redirect_url 参数。
我已经通过 guest() 函数正常登录解决了这个问题,但我不知道在这种情况下如何实现。
问题与此非常相似 post
最佳答案
关键函数是 guest()
和 intended()
:
guest()
创建对您选择的 URL 的重定向响应,理想情况下是您的登录页面,同时存储您所在的当前 url可以将您的用户重定向到,当后者成功完成身份验证过程。
intended()
在用户 之后获取预期的重定向 URL完成认证。
演示
Authenticate
中间件 - 用于验证访问 url 的用户是否已登录。
class Authenticate
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//check if user is not logged in.
if (Sentinel::check() === false) {
//If ajax, send back ajax response
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
//redirect guest to login page
return redirect()->guest('/login');
}
}
return $next($request);
}
}
RESTful UserController
,我们在其中处理所有登录尝试
/**
* POST: Login
*
* @param Request $request
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
public function postLogin(Request $request)
{
//Authenticate User if possible
if ($this->service->user->loginByEmail($request->only(['email','password','remember_me']))) {
//Authentication Successful - Redirect to url that guest was trying to access, else redirect to home page.
return redirect()->intended('/');
} else {
//Authentication error, redirect back to login page with input
return redirect('/login')->withErrors(['password_incorrect' => 'Your password is incorrect. Please try again.'])->withInput();
}
}
框架中已有的函数声明
Illuminate\Routing\Redirector
/**
* Create a new redirect response, while putting the current URL in the session.
*
* @param string $path
* @param int $status
* @param array $headers
* @param bool $secure
* @return \Illuminate\Http\RedirectResponse
*/
public function guest($path, $status = 302, $headers = [], $secure = null)
{
//Store current full URL in session
$this->session->put('url.intended', $this->generator->full());
//Redirect
return $this->to($path, $status, $headers, $secure);
}
/**
* Create a new redirect response to the previously intended location.
*
* @param string $default
* @param int $status
* @param array $headers
* @param bool $secure
* @return \Illuminate\Http\RedirectResponse
*/
public function intended($default = '/', $status = 302, $headers = [], $secure = null)
{
//Get path that guest was trying to access
$path = $this->session->pull('url.intended', $default);
//Redirect
return $this->to($path, $status, $headers, $secure);
}
关于php - 在 Laravel 中使用 Socialite 登录后重定向到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35022774/
我已经在 laravel 5.6 上使用 socialite 3.2.0 设置了一个 google 登录。身份验证确实工作得很好。我想要一个自定义重定向,我尝试了我最好的方法,但它在注册后重定向到主页
我目前正在将 Socialite 添加到我的网站以允许用户从 Facebook 登录。 public function redirectToProviderFacebook() { retur
我正在尝试将社交名流整合到网站中,但遇到了一个问题,这应该是一件相当琐碎的事情 - 在社交提供商进行身份验证后更改用户的重定向位置。 我将使用 Socialite 来执行三项操作: 注册 - 向提供商
我最近将我的应用程序移至实时服务器中。 问题是 Laravel Socialite 停止工作,解释如下: 我点击谷歌登录并选择电子邮件后,回调时会发生这种情况: Abstract.php 第 200
我正在使用 Laravel 的 Socialite 向应用程序添加社交身份验证。我可以检索全名,但不能分别检索名字和姓氏。回调发生后,Socialite 正在处理它,成功检索到用户。如果我要转储我从
我有一个使用 socialite 的应用程序,我想为 Github 身份验证创建测试,所以我使用 Socialite Facade 模拟调用 Socialite driver 方法,但是当我运行测试时
基本上我想从 Linkedin 获取用户个人资料链接。我将 Laravel Socialite 与 Socialite Providers 一起使用从 Linkedin 获取信息。 当用户成功重定向回
您好,我正在使用 Laravel Socialite 通过我的远程 Laravel Paspport 应用程序进行 Oauth 身份验证。成功获得用户身份验证后,当我想让用户进入应用程序时,它会将我重
Laravel Socialite有一个“无状态”模式,它禁止将任何内容存储到 session 中。从阅读源代码来看,它并没有做任何不同的事情——它只是不存储或检索这些值。 作为其中的一部分,它 as
我正在使用 Laravel 5.4 和 Socialite,因此我的用户可以使用 Facebook 登录。 我的网站使用子域 newyork.example.com, paris.example.co
我正在开发一个 flutter 应用程序,我想实现社交登录(谷歌和 Facebook)。 我的 API 是用 Laravel 实现的,并使用 Laravel-socialite 对用户进行身份验证,有
这里还有一个新问题,但希望有人能阐明一些: 我正在 Laravel 5 中使用 Socialite,我希望能够在用户登录后将用户重定向到网站上的页面。问题是使用 return redirect('an
在 Socialite 文档中,它说以下行获取用户信息: $user = Socialite::driver('twitter')->user(); 这自然假设回调源自 Twitter。但是,在某些情
我已经在我的应用程序中集成了 Laravel 默认身份验证,现在我想将社交登录与其集成。 这是工作流程 1.从社交名流获取用户详细信息(social_id,name,email,profile_pic
我做了什么: 添加 "laravel/socialite": "~2.0" 到 composer.json 运行 Composer 更新 添加提供者 'Laravel\Socialite\Social
Socialite(通过Socialite::driver(self::PROVIDER)->user())获取的access_token是有时间限制的,Google是一个小时. 我可以通过将重定向调
Laravel 5、Socialite 和 google/apiclient 软件包。 源代码:https://github.com/svpernova09/meatings 我让社交名流在 Goog
我尝试使用包 Laravel\Socialite在我的系统中 Lumen (5.1) 我在 config\services.php 中添加了这个文件 : [ 'client_id'
我正在尝试使用 laravel socialite 无状态选项通过 laravel api 后端集成社交登录,因为我正在使用 vuejs 构建一个单页应用程序,并且一切都是通过 http api 调用
我已收到 token-id来自谷歌生成的客户端安卓应用程序。 我如何向用户授权社交名流? 我现在正在使用 google_api 客户端,但它没有 Socialte 的便利。 最佳答案 如果您可以获得服
我是一名优秀的程序员,十分优秀!