Skip to content

feat: OIDC single sign-on per organization - #50

Merged
iRazvan2745 merged 4 commits into
masterfrom
feat/oidc-sso
Nov 29, 2026
Merged

iRazvan2745 merged 4 commits into
masterfrom
feat/oidc-sso

Conversation

@iRazvan2745

@iRazvan2745 iRazvan2745 commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Single sign-on

Settings → Single sign-on lets instance admins add OpenID Connect providers to an organization. Each provider claims one or more email domains, and no two providers can share a domain. People with an email on those domains sign in through the provider and join that organization as members.

  • Login: when a provider is enabled, the login form asks for the email first, then offers "Continue with ", the password field, or both.
    • SSO-only domains don't redirect automatically: "Use password instead" stays available so an instance admin can always get in, and the server refuses passwords from everyone else.
    • SSO failures come back to /login with next kept. account_not_linked gets its own message.
  • Providers: name, issuer, client ID/secret, domains, and three switches: enabled, allow password sign-in, link existing accounts.
    • The issuer's discovery document is checked when saving.
    • The client secret is encrypted and never returned.
    • The dialog shows the redirect URI before the first save.
  • Account linking: off by default. When it's on, the provider's emails count as verified, so a first sign-in attaches to the existing account with that email.
  • Better Auth: providers are registered from the database on each sign-in and callback, so every replica uses the current settings and nothing is cached across restarts.
    • The IdP can only sign in addresses on the provider's domains.
    • Bare ID-token sign-ins are refused.
    • /link-social goes through the same checks.
  • Concurrency: saves take a Postgres advisory lock, so two saves can't claim the same domain at once. Joining an organization takes one too, so two sign-ins at once can't add duplicate memberships.
  • API: oidc.* is closed to API keys and left out of the REST OpenAPI spec.
  • Migration: one new table, oidc_providers.

Tests

tests/api/oidc.test.ts runs a fake IdP and covers:

  • admin-only access, and no access through API keys
  • the secret staying write-only
  • domain conflicts
  • password lockout with the admin exception
  • redirect sign-in on a replica that never saw it start
  • the domain restriction
  • account linking
  • removed and disabled providers

Known gaps

  • Someone removed from the organization is added back on their next SSO sign-in.
  • The login form has no component test.
  • The docs page is still being written.

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@blacksmith-sh

This comment has been minimized.

@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The reviewed changes appear safe to merge, with both previous findings addressed.RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The reviewed changes appear safe to merge, with both previous findings addressed.

Summary

Adds organization-scoped OIDC sign-in, provider settings, and setup docs.

  • Instance admins can set up OIDC providers for organization email domains.
  • People can sign in through the provider for their email domain.
  • The docs landing page describes its authorship in broader terms.

Diagram

sequenceDiagram
    participant User
    participant Clowder
    participant Database
    participant IdP
    User->>Clowder: Enter email
    Clowder->>Database: Find enabled provider for domain
    Clowder-->>User: Offer allowed sign-in options
    User->>Clowder: Continue with provider
    Clowder->>Database: Load current provider
    Clowder-->>IdP: Redirect to sign in
    IdP-->>Clowder: Return authorization code
    Clowder->>Database: Reload current provider
    alt Provider enabled
        Clowder->>IdP: Exchange code and read identity
        Clowder->>Clowder: Check email domain and account linking
        Clowder->>Database: Join organization and create session
        Clowder-->>User: Open requested page
    else Provider removed or disabled
        Clowder-->>User: Return to login with saved next path
    end
Loading

Reviews (2) · Last reviewed commit: "docs: match the SSO guide to the setting..." · Reviewed by Greptile

Comment thread tests/api/oidc.test.ts Resolved
Comment thread packages/auth/src/oidc.ts Resolved
@iRazvan2745
iRazvan2745 merged commit 1bc2620 into master Nov 29, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant