Unify Laravel Authentication / Session Across Apps
Question: Is it possible to make single login authentication for multiple laravel apps on same domain?
Condition: Laravel stores session on two places: client-side on encrypted HTTP cookie and server-side on (optional) encrypted key-store value.
Idea: Make each apps reads the same session both on client-side and server-side and make sure both application reads same ‘users’ table.
How to unify client side:
- Open config/session.php
- Find ‘cookie’ parameter
- By default the value should be ‘laravel_session’. It’s okay to put there, or if you want you can change that to other name. Just note that this value must be same accross application
- Open .env
- Set same 32 string length APP_KEY for each application
- Install redis (if you have not)
- Install predis package (if you have not)
- Open .env
- Change CACHE_DRIVER to redis for each application
Well, there are other configurations to think of such as cookie domain, cookie path, session encryption, and redis clustering. You should look them if you need to.