当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Laravel5.3 multi-domain auth

问题描述:

  • PHP 7.0.10-2
  • nginx/1.10.0
  • Laravel Framework version 5.3.6


Hey guys, I'm trying to make cross-domain auth with several laravel application.

In config/session.php:

'connection' => 'default',

...

'domain' => env('SESSION_DOMAIN', '.baner-platform.local'),

SESSION_DOMAIN is not set in .env, so it uses value from php config.

In .env:

SESSION_DRIVER=redis

REDIS_HOST=127.0.0.1

REDIS_PASSWORD=null

REDIS_PORT=6379

When I open domain and subdomain page in redis-cli I see 2 session keys:

127.0.0.1:6379> keys *

1) "laravel:2GDEUYrVVIUhWbAG2PfaTQF5Hnotd6QYIvzG0Oo9"

2) "laravel:aNsivaryHAGm7TYXEIkofHGVWkJYCCdwdtczyjUn"

When im loggin on domain and refresh page on subdomain it loose session on domain and conversely.

For both applications I use one DB and one common model.

网友答案:

Finaly!

By default all laravel cookies are encrypted by midlware \App\Http\Middleware\EncryptCookies::class

so I've add session cookie to $except array: \App\Http\Middleware\EncryptCookies

 protected $except = [
        'laravel_session'
    ];
分享给朋友:
您可能感兴趣的文章:
随机阅读: