简体   繁体   English

Laravel子域重定向登录

[英]Laravel Subdomain Redirect With Login

I am fairly new to stack overflow so please stick with me here. 我是一个相当新的堆栈溢出所以请在这里坚持我。

I am creating a laravel project that has the following links... 我正在创建一个具有以下链接的laravel项目......

main.dev (This is for login, registration, and help sections for the user) main.dev(这是用于用户的登录,注册和帮助部分)

athlete.main.dev (This is for athletes to be redirected to upon main.dev login) athlete.main.dev(这是为运动员重定向到main.dev登录)

coach.main.dev (This is for coaches to be redirect to upon main.dev login) coach.main.dev(这是为了将教练重定向到main.dev登录)

Here is an idea of what the code looks like to redirect the user switch (User::getGroup()) { case 'Athlete': return Redirect::to(' http://athlete.main.dev '); case 'Coach': return Redirect::to(' http://coach.main.dev '); } 以下是重定向用户switch (User::getGroup()) { case 'Athlete': return Redirect::to(' http://athlete.main.dev '); case 'Coach': return Redirect::to(' http://coach.main.dev '); }的代码switch (User::getGroup()) { case 'Athlete': return Redirect::to(' http://athlete.main.dev '); case 'Coach': return Redirect::to(' http://coach.main.dev '); } switch (User::getGroup()) { case 'Athlete': return Redirect::to(' http://athlete.main.dev '); case 'Coach': return Redirect::to(' http://coach.main.dev '); }

This works fine and the user is redirected according to their account type, but upon arriving at this subdomain the user is currently forced to log in again. 这工作正常,用户根据其帐户类型重定向,但在到达此子域时,用户当前被迫再次登录。

I have been searching now for about three days trying to find the answer to no avail. 我一直在寻找大约三天试图找到答案无济于事。

Is it possible to automatically login the user upon arriving at these redirects based off of main.dev's login information? 是否可以根据main.dev的登录信息在到达这些重定向时自动登录用户? Or how can I share the session data across subdomains? 或者我如何跨子域共享会话数据?

Thanks for your help, -Nick 谢谢你的帮助, - 尼克

I think you will require a SSO (Single Sign-on) feature to solve your problem as you need to serve both the applications on different server, it can only be achieved using SSO. 我认为您需要一个SSO(单点登录)功能来解决您的问题,因为您需要为不同服务器上的两个应用程序提供服务,它只能通过SSO实现。 Take a look at this it maybe helpful to solve your issue - 看一下这可能有助于解决您的问题 -

Good single sign-on solution for Laravel Laravel的良好单点登录解决方案

One way to solve you problem is by sending the username and password to the url you want to redirect and make an Auth::attemp() in the subdomain to. 解决问题的一种方法是将用户名和密码发送到要重定向的URL,并在子域中创建一个Auth :: attempt()。

switch (User::getGroup()) {
            case 'Athlete':
                return Redirect::to('http://athlete.main.dev')->with([
                'username' => $username,
                'password' => $password
                ]);
            case 'Coach':
                return Redirect::to('http://coach.main.dev')->with([
                'username' => $username,
                'password' => $password
                ]);;
       }

In your controller that handles coach.main.dev and athlete.main.dev add this before you make anything else 在你的控制器处理coach.main.devathlete.main.dev添加该你做任何事情之前

if(isset($username) && isset($password)){
    Auth::attempt(['username' => $username, 'password' => $password]);
}

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

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