<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: forceki</title>
    <description>The latest articles on DEV Community by forceki (@forceki).</description>
    <link>https://dev.to/forceki</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3935277%2F9e2bb3b1-1eb0-44fb-a770-06628b78eb21.jpg</url>
      <title>DEV Community: forceki</title>
      <link>https://dev.to/forceki</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/forceki"/>
    <language>en</language>
    <item>
      <title>System Design: SSO Authentication Using Shared Cookie for Multiple Apps</title>
      <dc:creator>forceki</dc:creator>
      <pubDate>Sun, 17 May 2026 14:28:47 +0000</pubDate>
      <link>https://dev.to/forceki/system-design-shared-cookie-authentication-for-multiple-apps-49jn</link>
      <guid>https://dev.to/forceki/system-design-shared-cookie-authentication-for-multiple-apps-49jn</guid>
      <description>&lt;p&gt;Building a great product often means scaling your internal tooling. But as a company grows, a common architectural headache emerges: every single internal application from the Cashier dashboard to the Point of Sale (POS) system ends up with its own isolated login system. &lt;/p&gt;

&lt;p&gt;Before you know it, managing user credentials, sessions, and multi-app permissions becomes an absolute nightmare for both users and the security team.&lt;/p&gt;

&lt;p&gt;A few years ago, I tackled a project to solve exactly this by centralizing authentication across multiple internal applications. The goal was to transition the entire ecosystem into a single, unified system using a central &lt;strong&gt;SSO Engine &amp;amp; IAM Service&lt;/strong&gt; to handle complex, multi-app roles and permissions. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: I'm sharing this architectural breakdown and diagram because I've already received explicit permission to do so!&lt;/em&gt; 😉&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Architectural Flow Diagram
&lt;/h2&gt;

&lt;p&gt;Below is the complete sequence flow mapping out how the authentication state behaves across different subdomains. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5s9o8zodtvvkmrzfhs3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5s9o8zodtvvkmrzfhs3.jpg" alt="System Design: Shared Cookie Authentication Flow" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1: High-level overview of the request routing between Domain 1 (Cashier), Domain 2 (POS), and the central Identity Provider.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  How the Data Flows
&lt;/h2&gt;

&lt;p&gt;When mapping out this architecture, we compared two main approaches: &lt;strong&gt;Full Token Callback Flow (OAuth2/OIDC style)&lt;/strong&gt; and &lt;strong&gt;Shared Wildcard Cookies&lt;/strong&gt;. Because we were operating in a controlled, purely internal ecosystem sharing the exact same root domain (&lt;code&gt;*.domain.com&lt;/code&gt;), we opted for the Wildcard Cookie route. &lt;/p&gt;

&lt;p&gt;Here is exactly how it works under the hood:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. The Initial Authentication (Domain 1: Cashier)
&lt;/h3&gt;

&lt;p&gt;When a user first lands on &lt;code&gt;cashier.domain.com&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Frontend (FE) browser checks for existing cookie validity.&lt;/li&gt;
&lt;li&gt;If no valid authentication exists, the frontend triggers a redirect to the &lt;strong&gt;SSO Login Page&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The user inputs their credentials. The login page hands this over to the Cashier Backend API.&lt;/li&gt;
&lt;li&gt;The Backend API acts as a client, requesting authentication from the central &lt;strong&gt;SSO Engine &amp;amp; IAM Service&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Once verified, the SSO Engine returns all user permissions, metadata, and the session token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Magic Step:&lt;/strong&gt; The Cashier Backend API issues a &lt;code&gt;Set-Cookie&lt;/code&gt; header to the browser. Instead of scoping it strictly to &lt;code&gt;cashier.domain.com&lt;/code&gt;, it sets the cookie domain attribute to the wildcard root: &lt;code&gt;.domain.com&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Seamless Cross-Domain Access (Domain 2: POS)
&lt;/h3&gt;

&lt;p&gt;Now, when the same user navigates to &lt;code&gt;pos.domain.com&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Because the cookie was set at the root &lt;code&gt;.domain.com&lt;/code&gt; level, the browser &lt;strong&gt;automatically includes the cookie&lt;/strong&gt; in requests heading to the POS Frontend and Backend API.&lt;/li&gt;
&lt;li&gt;The POS Backend API captures this incoming cookie. &lt;/li&gt;
&lt;li&gt;To ensure strict validation, integrity, and up-to-date permissions, the Backend API securely forwards the cookie along with an &lt;code&gt;app_key&lt;/code&gt; and &lt;code&gt;secret_key&lt;/code&gt; directly to the central &lt;strong&gt;SSO Engine &amp;amp; IAM Service&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The SSO engine verifies the keys and the cookie, returning the specific permissions and tokens required for the POS domain.&lt;/li&gt;
&lt;li&gt;The session is seamlessly established without a single redirect or manual login prompt.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Why Wildcard Cookies? (Pros &amp;amp; Cons)
&lt;/h2&gt;

&lt;p&gt;While a Full Token Callback Flow (using authorization codes and state parameters) is the gold standard for public-facing third-party apps, it introduces significant engineering overhead, constant browser redirects, and callback route handling for every internal app you build.&lt;/p&gt;

&lt;p&gt;For our specific use case, &lt;strong&gt;Shared Wildcard Cookies&lt;/strong&gt; offered distinct advantages:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Pros:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero Redirect Fatigue:&lt;/strong&gt; Users transition between &lt;code&gt;cashier.&lt;/code&gt; and &lt;code&gt;pos.&lt;/code&gt; instantly. No jarring page blinks or auth redirects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Radical Simplicity:&lt;/strong&gt; Frontend applications don't need complex token-storage mechanisms (like dealing with &lt;code&gt;localStorage&lt;/code&gt; vs &lt;code&gt;sessionStorage&lt;/code&gt; XSS trade-offs). They simply let the browser do what it does best: manage cookies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Centralized Cryptographic Trust:&lt;/strong&gt; By enforcing that every backend API must validate the cookie alongside an &lt;code&gt;app_key&lt;/code&gt; and &lt;code&gt;secret_key&lt;/code&gt; against the central SSO engine, we eliminated the risk of downstream microservices blindly trusting stale data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Trade-offs to Keep in Mind:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tight Domain Coupling:&lt;/strong&gt; This strategy strictly requires your apps to live under the same top-level domain. If your app moves to &lt;code&gt;completely-different-domain.com&lt;/code&gt;, this mechanism breaks, and you'll have to implement standard token exchange.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CSRF Mitigation is Mandatory:&lt;/strong&gt; Because cookies are sent automatically by the browser, you &lt;em&gt;must&lt;/em&gt; implement robust Cross-Site Request Forgery (CSRF) defenses, ensure &lt;code&gt;HttpOnly&lt;/code&gt; and &lt;code&gt;Secure&lt;/code&gt; flags are strictly enforced, and set proper &lt;code&gt;SameSite&lt;/code&gt; policies (&lt;code&gt;Lax&lt;/code&gt; or &lt;code&gt;Strict&lt;/code&gt; depending on your cross-subdomain API interactions).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;When building internal tooling, over-engineering can be just as dangerous as under-engineering. Choosing a Shared Wildcard Cookie flow backed by a robust, server-to-server &lt;code&gt;app_key&lt;/code&gt; verification loop allowed us to ship a highly secure, centralized IAM ecosystem with minimal architectural friction.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>security</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
