# ADR-004: Works Square Owns The Desktop Authentication Lifecycle Boundary ## Status Accepted and implemented on 2026-08-19; amended on 2026-10-10. ## Context The desktop client obtained tokens from Works Square but refreshed them directly against the custom identity service with an embedded OAuth client secret. That mixed issuer/client boundary made rotation dependent on two independently configured clients and could turn an otherwise valid persisted session into `invalid_grant`, returning the user to the login page hours later. The platform account system now exposes a standard OIDC issuer for the public platform identity while the existing Works Square password/mobile facade remains available for its legacy path. ## Decision - Renderer sends authentication operations only to Electron Main. - Electron Main owns access/refresh tokens, encrypted persistence, refresh rotation, terminal failure cleanup, and the seven-day inactivity policy. - Optional remembered username/password data is a separate Electron Main record. Packaged builds encrypt it with OS-protected storage; it is never Renderer-persisted or stored by Works Square. - Platform account login uses Main-owned Authorization Code + PKCE against the configured platform OIDC issuer: system browser, exact `niancode://auth/callback`, state/nonce/S256 validation, and a registered public Makelore client without a secret. Main owns the code exchange and all resulting tokens. - Legacy password/mobile login, refresh, and logout use fixed Works Square `/api/auth/*` endpoints. - Works Square owns the confidential upstream OAuth client configuration and proxies the lifecycle to the identity service. - The desktop bundle must not contain a confidential OAuth client secret or call the custom one-feel identity service directly; platform OIDC access remains behind the Main boundary and uses the configured standard issuer. - Logout and mobile login preserve remembered-password data. A successful password login with the option cleared removes the previous record; unavailable secure storage disables the option. ## Consequences - The matching Works Square server endpoints must be deployed before this client is released. - The packaged client must receive `PLATFORM_AUTH_ISSUER` and the registered Makelore client/redirect configuration before platform login can be released; no username, email, or legacy identifier is used to rebind a platform subject. - OAuth credential rotation or upstream endpoint changes are server-side configuration changes rather than desktop releases. - A terminal refresh `400` or `401` still fails closed and clears the local session; transient failures preserve the established retry behavior. - Remembered-password persistence is convenience behavior rather than session authority. Its failure must not grant authentication or move password persistence to Works Square/Renderer. - Packaged Windows and signed macOS still require a smoke covering save, restart restore, unchecked-login clear, and the absence of a development Keychain prompt. ## Evidence - Source commit: `dc776ff` - Integration merge: `f52c2c8` - Feature verification: 2,190 client tests passed, typecheck passed, Vite build passed, and lint reported no errors. - Remember-password source/integration: `990639f` / `2b9f84e`; 79 focused tests, typecheck, scoped lint, and Renderer/Main/Preload/utility build passed.