[英]Laravel share session same domain as a module
I have a problem with the session share with my 2 laravel projects. 我的2个laravel项目的会话共享有问题。 My first project is portal.blabla.test and my other project is billing.blabla.test. 我的第一个项目是portal.blabla.test,其他项目是billing.blabla.test。
Portal is the authentification. 门户是身份验证。 Billing is a module loaded inside portal. 计费是门户中加载的模块。
I load the billing module inside portal project using ajax and i can't make the session share. 我使用ajax将计费模块加载到门户项目中,但是我无法进行会话共享。 Auth::check() doesn't work. Auth :: check()不起作用。
But, if i load the page manually in my browser (billing.blabla.test), i am logged in. It seems there is some issue when integrating my module inside another laravel project sharing the same auth. 但是,如果我在浏览器(billing.blabla.test)中手动加载页面,则我已经登录。将模块集成到共享相同身份验证的另一个laravel项目中时,似乎存在一些问题。
I added cors for cross website sharing, i try sending the csrf token on the ajax call, i try changing the value 'same_site' in session.php for "lax". 我为跨网站共享添加了cors,我尝试在ajax调用中发送csrf令牌,我尝试将session.php中的“ same_site”值更改为“ lax”。
I did this for both projects inside session.php using session_driver database: 我使用session_driver数据库对session.php中的两个项目进行了此操作:
return [
//...
' domain' => '.blabla.test'
];
Here is how i load the module : 这是我如何加载模块:
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
url: "https://billing.blabla.test/billing",
success: function(data) {
$('#content-module').html(data);
}
});
This is my page being loaded : 这是我正在加载的页面:
{{ Auth::check() }}
I see an empty page when the module is loaded but when going https://billing.blabla.test/billing , i can see '1'. 加载模块时,我看到一个空白页,但是当转到https://billing.blabla.test/billing时 ,我可以看到“ 1”。
You have to put a wildcard subdomain to your session.php config's file, like that : 您必须将一个通配符子域放到session.php配置文件中,如下所示:
<?php
return [
//...
'domain' => '.blabla.test'
];
Like that you can share your session between subdomains :) 这样,您可以在子域之间共享会话:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.