# Share one sign-in across every host name

> A realm reached under several host names can share one sign-in across them, and present one issuer to every app.

A realm can be reached under more than one host name, such as a regional name beside a global one:
`foobar.cvyuh.com` and `foobar-eu.cvyuh.com`. You can give users one session across those names, and give every app
the same issuer, whichever name it uses.

**Before you start:**

- **Who can do it:** a realm administrator, in a group that holds `RealmOwner`
  ([Delegated administration](/platform/realms/delegated-administration/)). `RealmViewer` can read the settings but
  not change them.
- **Where:** today this is done through the API; [Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`.
- **First:** the realm answers on each host name, as [Hostnames](../../../../platform/realms/hostnames/) describes.

## How it behaves

**One session, where the cookie reaches.** The session cookie is set only on the host the user signed in on, unless
the platform names cookie domains (`cookieDomains`). Host names under one of those domains share the session: signed
in on one, signed in on all, and one sign-out ends it everywhere. Host names under different domains each sign the
user in separately.

**One issuer, if you want it.** By default each host name is its own issuer, so an app using `foobar-eu.cvyuh.com` sees
tokens from `https://foobar-eu.cvyuh.com/oauth2`. With a base URL set, every app sees the same issuer, and the discovery
document, its endpoints, the issuer in tokens and the return links are all built on that one address. Host names that
differ only in letter case or port are already the same issuer.

| Your apps… | Base URL |
|---|---|
| each use one host name | Not needed |
| may use either host name, and check the issuer | Set it |
| call APIs that trust exactly one issuer | Set it |

## Set it up

<Steps>

1. Check the realm answers on each host name. Each one serves its own discovery document:

   ```sh
   curl https://foobar-eu.cvyuh.com/oauth2/.well-known/openid-configuration
   ```

2. Set the base URL:

   ```sh
   curl 'https://foobar.cvyuh.com/api/v0/am/objects/v1/baseUrl?id=baseUrl' \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "url": "https://foobar.cvyuh.com" }'
   ```

   It must be an `https` origin: lower-case host, an optional port other than 443, no path, no trailing slash.

</Steps>

## Check it worked

Open `https://foobar.cvyuh.com/oauth2/.well-known/openid-configuration` and
`https://foobar-eu.cvyuh.com/oauth2/.well-known/openid-configuration`. With a base URL set, both show the same `issuer`.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| Saving the base URL is refused | It isn't an `https` origin: upper-case letters, port 443 written out, a path or a trailing slash | Write it as `https://foobar.cvyuh.com` |
| Users sign in again on the second host name | The host names aren't under one cookie domain | Expected: a base URL shares the issuer, not the session |
| An app rejects tokens after the change | It checks the old issuer | Update the app's issuer to the base URL |

## Change it later

`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/baseUrl/baseUrl` with a new `url`.

<Aside type="caution" title="Changing the base URL changes the issuer">
  Every app sees the new issuer at once. Tell the owners of apps that check the issuer first.
</Aside>

## Related

- [Realm base URL](../../../../platform/realms/realm-base-url/): the setting and its rules.
- [Discovery document](../../../applications/registration/discovery/): what apps read from the realm.
