# How to achieve SSO for multiple apps that do not share a root domain, which causes cookie issues?

**URL:** <https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860>\
**Category:** Get Help\
**Created:** [November 27, 2021, 6:31pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860 "2021-11-27T18:31:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FullStackFool](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fullstackfool/32/25823_2.png) [@FullStackFool](https://community.auth0.com/u/FullStackFool)\
**Post date:** [November 27, 2021, 6:31pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860/1 "2021-11-27T18:31:17Z")

</div>

The stack:

- Universal login (pure, no custom templates).
- Multiple SPAs all using auth0.js, all on different domains:
  - [app1.com](http://app1.com)
  - [app2.com](http://app2.com)

- Custom domain for auth server.
  - [auth.app3.com](http://auth.app3.com)

The above is working, most of the time. Problems start to occur when the user has banned third-party cookies - for instance when using a privacy/incognito mode. But a lot of users just prefer to browse with strict settings.

I know the immediate suggestion is to ensure all SSO apps remain on the same domain, eg:

- [app1.example.com](http://app1.example.com)
- [app2.example.com](http://app2.example.com)

But this is an un-preferred option for us, given the effects on SEO, etc.

So, is there a solution to this issue?

---

<div class="post-metadata">

**Author:** ![FullStackFool](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fullstackfool/32/25823_2.png) [@FullStackFool](https://community.auth0.com/u/FullStackFool)\
**Post date:** [November 27, 2021, 7:56pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860/2 "2021-11-27T19:56:59Z")

</div>

JS client settings:

- cacheLocation = ‘localstorage’
- useRefreshTokens = true/false (no difference)

---

<div class="post-metadata">

**Author:** ![FullStackFool](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/fullstackfool/32/25823_2.png) [@FullStackFool](https://community.auth0.com/u/FullStackFool)\
**Post date:** [December 1, 2021, 10:03pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860/3 "2021-12-01T22:03:01Z")

</div>

Right, FINALLY got there!!

For anyone having issues with Safari, Brave, or incognito/private modes in an SPA, here is the checklist.

**In SPA application settings (Auth0 dashboard):**

- Add app URL to “ **Callback URLs** ” (cannot be “localhost” if developing - use a local alias for your dev server)
- Switch on “ **Refresh Token Rotation** ”

**In API settings (Auth0 dashboard):**

- Switch on “ **Allow Skipping User Consent** ”
- Switch on “ **Allow Offline Access** ”

**In SPA code (this is after the login, when the auth server is redirecting back to your SPA):**

```auto
const client = new Auth0Client({
    domain: ' ******',
    client_id: ' ******',
    cacheLocation: 'localstorage',
    useRefreshTokens: true,
    audience: ' ******' // The audience MUST be passed here.
});

await client.handleRedirectCallback();

const apiToken = await client.getTokenSilently({
     audience: ' ******', // This MUST match the audience above.
});

```

The issue I ran into was not passing the audience to the Auth0Client. At that stage it’s not really needed as you are retrieving an id-token for the frontend. However, the refresh token returned is the one used when generating the API token (in `getTokenSilently`). So the audience in the original refresh token MUST match the one used in `getTokenSilently`.

I’ve requested the docs be improved.

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [December 2, 2021, 3:32pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860/4 "2021-12-02T15:32:19Z")

</div>

Thanks for posting the solution!

John

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 7, 2021, 2:24pm UTC](https://community.auth0.com/t/how-to-achieve-sso-for-multiple-apps-that-do-not-share-a-root-domain-which-causes-cookie-issues/73860/5 "2021-12-07T14:24:56Z")

</div>


