Yii2 多个子域名开启 SSO 单点登录

19-11-12 13:48 字数 634 阅读 1318 已编辑

要求

两个域名一个 www.shiqidu.com 、一个 store.shiqidu.com,要求用户在 www.shiqidu.com 登录后,打开 store.shiqidu.com 后直接是登录状态,不用重新登录。

实现

  1. 修改 www.shiqidu.com 项目的 config/main.phpidentityCookie,增加 domain 配置。
'user'  => [
    'identityCookie'  => ['name' => '_identity-frontend', 'httpOnly' => true, 'domain' => '.shiqidu.com'],
],
  1. 修改 store.shiqidu.com 项目的 config/main.php,跟上面一样。
'user'  => [
    'identityCookie'  => ['name' => '_identity-frontend', 'httpOnly' => true, 'domain' => '.shiqidu.com'],
],
  1. 修改 store.shiqidu.com 项目的 config/main-local.phpcookieValidationKey
'components' => [
    'request' => [
        // 改为和 www.shiqidu.com 项目的一样
        'cookieValidationKey' => 'JpMmgd4PC2X1bf6BpRrzVT-fjGsfZv9s',
    ],
],

这是最简单的做法,当然你也可以自己写代码获取 cookie,然后自己写自动登录的代码。

1人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
191
收藏
31
排名 : 1
访问 : 128.3万
私信