Cross-subdomain auth: shared login session across standalone apps #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Each standalone app (main app at
demo.aiolabs.dev, Castle atcastle.demo.aiolabs.dev, Events atevents.aiolabs.dev) has its own localStorage namespace, so users must log in separately on each one.Currently auth stores the LNbits access token in
localStorageunder the keylnbits_access_token. Since localStorage is isolated per origin, there's no session sharing across subdomains.Current Workaround
Standalone apps accept a
?token=<access_token>URL parameter. The main app can link tocastle.demo.aiolabs.dev?token=xxxto relay the user's session. The token is stored in the target app's localStorage and the parameter is stripped from the URL.This works for demo purposes but is not production-grade:
Proposed Solution: Cookie-based auth
Backend (LNbits)
POST /auth), set anHttpOnlycookie alongside the JSON response:Domain=.aiolabs.devensures all subdomains receive the cookie automaticallyFrontend
credentials: 'include'to all fetch calls insrc/lib/api/lnbits.tsKey files
src/lib/config/lnbits.ts— token storage helperssrc/lib/api/lnbits.ts— API client with auth headerssrc/modules/base/auth/auth-service.ts— auth service login/logout flowConsiderations
Moved to aiolabs/webapp#28 with updated approaches (route-based modules as near-term solution).