Laravel子域:跨所有子域的单一身份验证不起作用? [英] Laravel subdomain: single auth across all subs not working?

查看:73
本文介绍了Laravel子域:跨所有子域的单一身份验证不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用动态子域系统(例如(name.domain.com))构建站点.我正在使用带有laravel的serve命令的Ubuntu.

I'm building a site with a dynamic subdomain system eg (name.domain.com). I'm using Ubuntu with laravel's serve command.

我已经按照我的路线进行了设置:

ive set it all up in my routes as so:

Route::domain('{x}.localhost')->group(function (){
    Route::get('/url/',  'SomeController@someAction')->middleware('can:xyz,x')->name('someName');
});

现在,除了Auth已被子域锁定的事实之外,一切都很好用

Now, everything works great, apart from the fact Auth is subdomain locked

eg(xyz.localhost:8000/,localhost:8000/)需要单独的登录名.

eg(xyz.localhost:8000/ , localhost:8000/) require separate logins.

在阅读了一些谷歌搜索信息之后,我可以在"domain"下的config/session.php文件中覆盖它.因此,在我的.env文件中,我为SESSION_DOMAIN设置了一个新的变量,并将其指向".localhost".或".localhost:800"或者只是为了测试,我得到了与IP 127.0.0.1/:8000相同的建议,但是,当我尝试登录时,我的会话在登录后是无效的,例如(我登录并重定向到正确的路由,但是我的身份验证捕获了该错误我尚未登录)

after a bit of googling I read, I can overwrite this in the config/session.php file under 'domain'. So in my .env file I set up a new var for SESSION_DOMAIN and point it to ".localhost" or ".localhost:800" or just for testing I get the same with the IP 127.0.0.1 / :8000 as suggested however when I try to login my session is not valid right after login eg( i log in and get redirected to the correct route but my auth catches that I'm not logged in)

会话配置

'domain' => env('SESSION_DOMAIN', null),

我的.env

SESSION_DOMAIN=.localhost

似乎由于某种原因未设置cookie?

It seems like no cookies are being set for some reason?

也许应该注意到这同时发生在使用文件和数据库进行会话中,我还每次都清除了缓存和会话存储以及cookie等.

Should probably note this is happening using both files and the database for sessions, I've also cleared out my cache and session storage each time along with cookies, etc.

-在过去的几天里,我尽力想出的一切办法来解决这一问题,但没有任何运气.即使是全新安装的laravel,也存在相同的问题.

-- I've tried everything I can think of over the last few days to solve this with no luck. Even on a fresh install of laravel the same issue is there.

我可以在主URL上使用FF登录,但是在子URL上我没有登录,如果尝试可以得到419.

I can log in with FF on the main URL, but on the sub URL I'm not logged in and I get a 419 if I try.

有什么建议吗?亲切的问候,马特

Any suggestions? Kind regards, Matt

-编辑

要在新安装的laravel上重现,请首先安装auth软件包:

To reproduce on a new install of laravel, first, install the auth package:

composer require laravel/ui

php artisan ui vue --auth
npm run dev

接下来,使用Mysql数据库信息编辑.env文件,并将以下行添加到文件中:

Next, edit your .env file with your Mysql database info and add this line to the file:

SESSION_DOMAIN=.localhost

最后将其添加到您的web.php路由文件中.

Last of all add this to your web.php routes file.

Route::domain('{foobar}.localhost')->group(function (){
    Route::get('/test/',  'HomeController@index');
});

(我想在此处在命令行中创建一个帐户) 然后推送默认迁移,并运行服务器并通过登录主页然后登录任何子域进行测试.

(i like to create an account here in the command line) Then push the default migrations and run the server and test by logging in on the home page and then any subdomain.

推荐答案

由于本地域,所以最好使用虚拟域(例如something.test),然后设置SESSION_DOMAIN = .something.test并清除缓存.本地主机和127.0.0.1的来源不同,因此无法设置会话.

Well its because of the localhost domain, instead use virtual domain like something.test and then set SESSION_DOMAIN=.something.test and clear out cache. localhost and 127.0.0.1 are not same origin so cannot set session.

这篇关于Laravel子域:跨所有子域的单一身份验证不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆