Jibato
Jibato

Reputation: 493

How to share authentication between multiple Symfony applications (same db, multiple Kernels)?

I have a Symfony 3 project that is split in 3 apps (multiple Kernels, same database, different subdomains) : Front / Admin / Partner. (Mainly did it to be able to use several Sonata Admin configs.)

When a user fill the login form in Front app, he is redirected to the corresponding app (subdomain) depending on his role.

My question is : how to make him authenticated after this redirection ?

Upvotes: 0

Views: 2104

Answers (2)

Tsounabe
Tsounabe

Reputation: 2184

To make it works i needed to add handler_id: session.handler.native_file in session section and to share session between sub domains i needed to prefix by a dot the domain in cookie_domain section:

framework:
    session:
        handler_id: session.handler.native_file
        save_path: '%kernel.project_dir%/var/sessions/'
        cookie_domain: .mywebsite.com

Upvotes: 1

Jibato
Jibato

Reputation: 493

I found why it was not working : my var folder was split by app therefore my sessions folder was not shared between apps.

 var
   |-- admin
   |    |-- cache
   |    |-- logs
   |    |-- sessions
   |-- front
   | ...

The solution was to define the same save_path in my apps session configs.
I also had to define the cookie_domain to hostname (without subdomain) in order to get one PHPSESSID cookie shared by all subdomains :

framework:
    session:
        save_path: '%kernel.project_dir%/var/sessions/'
        cookie_domain: 'mywebsite.com'

Upvotes: 1

Related Questions