Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Single sign-on with OIDC

Drusite signs people in through any OpenID Connect provider. Each provider is a table of its own, [auth.oidc.<id>], where <id> is a name you choose (lowercase letters, digits and _). You can have several, each with its own button on the sign-in page. Authentik, Keycloak and Google are the examples here; Zitadel, Kanidm, Authelia, Okta, Entra ID and Auth0 are set up the same way.

What you need from the provider

  • A client (an “application” or “OAuth2 provider”) of the confidential kind, with the authorization code flow. Drusite uses PKCE too.

  • Its redirect URI set to:

    https://notes.example.com/api/v1/auth/oidc/<id>/callback
    

    with your public_url and the <id> you chose. It must match exactly.

  • The issuer, the client ID and the client secret.

  • The scopes openid, email and profile. Drusite needs the email, and whether the provider verified it (email_verified).

How accounts are matched

  • Someone is known by the pair (provider, subject), never by email. Changing an email at the provider keeps the same Drusite account.
  • First sign-in, when nobody has that subject yet:
    • with auto_create = true, an account is made;
    • with link_by_verified_email = true, it joins the existing account with the same email, but only if the provider says it verified the email and the existing account’s email is verified too. Turn it on only for a provider that checks emails properly: anyone who could make an account there with your email could otherwise take over your Drusite account;
    • otherwise, the sign-in is refused, unless the person has an invitation for that verified email.
  • Every sign-in checks allowed_groups and allowed_email_domains, so removing someone from a group at the provider stops their next sign-in.

Groups only gate sign-in. They decide who may sign in through a provider, not what anyone can do once in. Roles in a workspace come only from invitations and invite links. Devices that are already signed in stay signed in until their tokens lapse (device_idle_days); sign them out from the account page, or delete the account, to cut someone off at once.

Authentik

  1. In the admin interface, Applications → Providers → Create → OAuth2/OpenID Provider.
    • Client type: Confidential.
    • Redirect URIs: https://notes.example.com/api/v1/auth/oidc/authentik/callback (strict).
    • Scopes: keep openid, email and profile. Authentik’s default profile mapping puts the user’s groups in a groups claim.
  2. Applications → Applications → Create, named Drusite, with that provider. Bind the groups or users that may use it, if you like: Authentik then refuses others itself.
  3. Copy the client ID and secret. The issuer is shown on the provider’s page as OpenID Configuration Issuer, ending in a slash.
[auth.oidc.authentik]
display_name = "Authentik"
issuer = "https://auth.example.com/application/o/drusite/"
client_id = "CLIENT-ID"
client_secret_file = "/run/secrets/oidc-authentik"
auto_create = true
# allowed_groups = ["notes"]

The issuer must be exactly what the provider says, trailing slash included. Authentik’s has one; a missing slash fails discovery.

Keycloak

  1. In your realm, Clients → Create client: OpenID Connect, client ID drusite.
  2. Client authentication on, Standard flow on, other flows off.
  3. Valid redirect URIs: https://notes.example.com/api/v1/auth/oidc/keycloak/callback.
  4. From Credentials, copy the client secret.
  5. For allowed_groups: Client scopes → drusite-dedicated → Add mapper → By configuration → Group Membership, token claim name groups, Full group path off, Add to ID token on.
[auth.oidc.keycloak]
display_name = "Keycloak"
issuer = "https://sso.example.com/realms/example"
client_id = "drusite"
client_secret_file = "/run/secrets/oidc-keycloak"
auto_create = true
# allowed_groups = ["notes"]

Keycloak’s issuer has no trailing slash. Users need an email, marked verified in Keycloak (or email_verified is false, which matters for allowed_email_domains, invitations and link_by_verified_email).

Google

  1. In the Google Cloud console, APIs & Services → OAuth consent screen: set it up for your users (Internal, for a Google Workspace organization, keeps it to your domain).
  2. Credentials → Create credentials → OAuth client ID, type Web application.
  3. Authorized redirect URIs: https://notes.example.com/api/v1/auth/oidc/google/callback.
[auth.oidc.google]
display_name = "Google"
issuer = "https://accounts.google.com"
client_id = "1234567890-abc.apps.googleusercontent.com"
client_secret_file = "/run/secrets/oidc-google"
auto_create = true
allowed_email_domains = ["example.com"]

Google has no groups claim, so use allowed_email_domains (verified emails only) to say who may sign in, or leave auto_create off and invite people.

Every setting

KeyDefault
display_namerequiredThe button’s label
issuerrequiredExactly as the provider states it; must be https
client_id, client_secretrequired, noneLeave the secret out for a public client
scopes["openid", "email", "profile"]Must include openid
auto_createfalseMake an account on first sign-in
link_by_verified_emailfalseSee above
allowed_email_domains[] (any)Only verified emails in these domains
allowed_groups[] (any)Only members of these groups
groups_claim"groups"The ID token’s claim that lists them
enabledtrueHide the provider without deleting its settings

The configuration reference has them all, with their environment variables (DRUSITE__AUTH__OIDC__KEYCLOAK__CLIENT_SECRET_FILE, say).

When it fails

The sign-in page says what went wrong, and the server’s log says more. The common cases are in Troubleshooting.