1791072000_oauth_clients.sql 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. -- RFC 7591 dynamic client registration / RFC 7592 client management.
  2. --
  3. -- Forward-only: deterministic, no DROP / down path. Redirect URIs are
  4. -- deliberately NOT stored on this row; they live in the `redirect_uris`
  5. -- catalog plus the `client_redirect_uris` join (todo 9).
  6. --
  7. -- The `UNIQUE (client_id)` table constraint (not merely a unique index) is
  8. -- required because `client_redirect_uris.client_id` references this column,
  9. -- and PostgreSQL only accepts a unique *constraint* as a foreign-key target.
  10. CREATE TABLE oauth_clients (
  11. id uuid NOT NULL,
  12. client_id text NOT NULL,
  13. client_secret_hash text NULL,
  14. client_secret_expires_at timestamptz NULL,
  15. client_id_issued_at timestamptz NOT NULL,
  16. client_name text NOT NULL,
  17. grant_types text[] NOT NULL,
  18. response_types text[] NOT NULL,
  19. scope text NOT NULL,
  20. token_endpoint_auth_method text NOT NULL,
  21. jwks jsonb NULL,
  22. jwks_uri text NULL,
  23. tls_client_auth_subject_dn text NULL,
  24. tls_client_auth_cert_thumbprint text NULL,
  25. request_uris jsonb NULL,
  26. contacts jsonb NULL,
  27. software_id text NULL,
  28. active bool NOT NULL DEFAULT true,
  29. registration_access_token_hash text NULL,
  30. created_at timestamptz NOT NULL,
  31. updated_at timestamptz NOT NULL,
  32. CONSTRAINT oauth_clients_pkey PRIMARY KEY (id),
  33. CONSTRAINT ux_oauth_clients_client_id UNIQUE (client_id)
  34. );
  35. -- A client certificate (subject DN or SHA-256 thumbprint) authenticates at
  36. -- most one client; NULL means "not enrolled" and is unconstrained, so a
  37. -- partial unique index is required (todo 21 relies on the ambiguity being
  38. -- rejected at write time).
  39. CREATE UNIQUE INDEX ux_oauth_clients_tls_subject_dn
  40. ON oauth_clients (tls_client_auth_subject_dn)
  41. WHERE tls_client_auth_subject_dn IS NOT NULL;
  42. CREATE UNIQUE INDEX ux_oauth_clients_tls_cert_thumbprint
  43. ON oauth_clients (tls_client_auth_cert_thumbprint)
  44. WHERE tls_client_auth_cert_thumbprint IS NOT NULL;