Guides

Sign in with Keycloak

Let people sign in to Home Space with their Keycloak account. Home Space registers as a confidential client of a realm and creates each user on first sign-in.

Optional

Single sign-on is not needed to run Home Space: by default users sign in with a username and password. Finish Install the server and nginx first, and create an administrator with a password, so you still have a way in while you set this up.

You need a Keycloak (version 20 or newer; the steps follow the Keycloak 26 admin console) that the Home Space server can reach over HTTPS, for example at https://auth.example.com. Running Keycloak itself is outside this guide: see the Keycloak documentation. Run it apart from the Home Space compose file.

1. Pick a realm

Use an existing realm with your users, or create one: in the admin console open the realm list, choose Create realm and name it, for example homespace. The realm's issuer URL is then:

issuer
https://auth.example.com/realms/homespace

Open https://auth.example.com/realms/homespace/.well-known/openid-configuration in a browser: if it shows JSON, the issuer is right.

2. Create the client

  1. Go to Clients → Create client.
  2. General settings: client type OpenID Connect, client ID homespace, name Home Space. Next.
  3. Capability config: turn Client authentication on (a confidential client), keep Standard flow on, and turn Direct access grants off. Next.
  4. Login settings:
    • Root URL: https://files.example.com
    • Valid redirect URIs: https://files.example.com/api/v1/auth/oidc/callback
    Save.
  5. Optional, recommended: on the client's Advanced tab, set Proof Key for Code Exchange Code Challenge Method to S256. Home Space always sends PKCE; this makes Keycloak insist on it.
  6. On the Credentials tab, copy the Client secret.

That one redirect URI covers every client: the web, desktop and mobile apps all finish sign-in through the server.

3. Limit access to a group (optional)

Without this, every user of the realm can sign in. To allow only a group, such as family:

  1. Groups → Create group, name it family, and add the members under Members.
  2. Put the groups into the ID token: Clients → homespace → Client scopes → homespace-dedicated → Configure a new mapper → Group Membership.
  3. Name groups, token claim name groups, Full group path off, Add to ID token on. Save.

4. Configure Home Space

Add these lines to /opt/homespace/.env:

.env
HOMESPACE_PUBLIC_URL=https://files.example.com
HOMESPACE_OIDC_ISSUER=https://auth.example.com/realms/homespace
HOMESPACE_OIDC_CLIENT_ID=homespace
HOMESPACE_OIDC_CLIENT_SECRET=paste-the-client-secret-here
HOMESPACE_OIDC_NAME=Keycloak
# Only with step 3:
HOMESPACE_OIDC_REQUIRED_GROUP=family

Recreate the server and watch it start:

shell
cd /opt/homespace
sudo docker compose up -d --force-recreate server
sudo docker compose logs -f server

The log says single sign-on enabled once the server has read the provider's configuration. The sign-in page now has a Keycloak button next to the password form.

5. First sign-in and administrators

A Home Space user is created the first time someone signs in, named after their Keycloak username (preferred_username), or the part of their e-mail before the @; a number is added if the name is taken. Accounts are matched on Keycloak's stable user id, never on the e-mail address.

New users are regular users. Make someone an administrator in the web administration, or on the command line:

shell
sudo docker compose exec server homespace-ctl user admin alice

Single sign-on only

To turn the password form off, add HOMESPACE_PASSWORD_LOGIN=false to .env and recreate the server. Local accounts can then still sign in with a passkey. Before you do, sign in once through Keycloak and make that account an administrator, or you lock yourself out of the administration.

Troubleshooting

SymptomCause
The server exits with discovering the OpenID Connect providerThe container cannot reach the issuer URL, or it is wrong. It must match exactly, without a trailing slash, and be reachable from inside the container: sudo docker compose exec server getent hosts auth.example.com.
… must use httpsThe issuer and HOMESPACE_PUBLIC_URL must be https:// (plain http works for localhost only).
Keycloak shows Invalid parameter: redirect_uriThe redirect URI in Keycloak differs from HOMESPACE_PUBLIC_URL + /api/v1/auth/oidc/callback.
Members of the group are refusedThe groups mapper is missing, adds the full path (/family), or does not add the claim to the ID token.