Passport-local: Authentication on different subdomain

Created on 4 Jan 2013  路  5Comments  路  Source: jaredhanson/passport-local

Hi Jared.
I would like to know if there is some way to move authentication form to a different subdomain.
When user tries to access restricted area he is redirected to auth. subdomain and asked to enter username, password. When done he is redirected back to where he wanted.

Most helpful comment

You can use: domain: ".app.localhost" and it will work. The 'domain' parameter needs 1 or more dots in the domain name for setting cookies. Then you can have sessions working across localhost subdomains such as: api.app.localhost:3000.

All 5 comments

Cookies can be configured to apply to subdomains if they are set on the root domain.
For example: a cookie set on google.com will apply to google.com, search.google.com, and maps.google.com.
See HTTP cookie - Domain and Path on wikipedia for more info.

For me, it seems that the path is / by default.

Cookies are handled by Express, check out the documentation on cookies.
You can set cookie defaults when you create the express session:

app.use(express.session({ secret: 'keyboard cat', cookie: { maxAge: 43200000 } }));

Hope that helps, cheers.

Setting the cookie domain via options passed to express.session did not work for me.

i.e.:

cookie: { maxAge: ONE_DAY, domain: '.mydomain.com' }

Login sessions are destroyed when navigating between apps on different subdomains.

Cannot Passport share login sessions across subdomains?

Please see closing comment in referenced passport issue above.

You can use: domain: ".app.localhost" and it will work. The 'domain' parameter needs 1 or more dots in the domain name for setting cookies. Then you can have sessions working across localhost subdomains such as: api.app.localhost:3000.

No, it doesn't help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

jcyh0120 picture jcyh0120  路  3Comments

JonathanSum picture JonathanSum  路  11Comments

EvHaus picture EvHaus  路  25Comments

jacargentina picture jacargentina  路  7Comments