1791504000_resource_servers.sql 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- RFC 8707 resource indicators and the per-client JWT access-token selector.
  2. --
  3. -- Forward-only: deterministic, no DROP / down path. This migration creates
  4. -- schema ONLY (the `resource_servers` catalog is created EMPTY and populated at
  5. -- runtime) and adds one additive column to `oauth_clients`.
  6. --
  7. -- There is deliberately NO grants/audience column here: grant, access-token,
  8. -- and refresh-token audience is security-ephemeral and lives in Redis, never in
  9. -- a Postgres row.
  10. -- Runtime-managed resource-server (resource indicator) catalog. `identifier`
  11. -- is the RFC 8707 resource identifier (`resource` parameter / `aud` target) and
  12. -- is globally unique, mirroring the `scopes` / `redirect_uris` catalogs.
  13. CREATE TABLE resource_servers (
  14. id uuid NOT NULL,
  15. identifier text NOT NULL,
  16. description text NOT NULL DEFAULT '',
  17. enabled bool NOT NULL DEFAULT true,
  18. created_at timestamptz NOT NULL,
  19. CONSTRAINT resource_servers_pkey PRIMARY KEY (id),
  20. CONSTRAINT ux_resource_servers_identifier UNIQUE (identifier)
  21. );
  22. -- Per-client access-token format. `opaque` is the OAuth 2.1 baseline and the
  23. -- default, so every existing client backfills to it (the CHECK applied after
  24. -- the ADD COLUMN validates the defaulted rows); `jwt` is honored only while JWT
  25. -- access tokens are enabled by configuration. Additive, so old replicas ignore
  26. -- the column during the expand/contract rollout.
  27. ALTER TABLE oauth_clients
  28. ADD COLUMN access_token_format text NOT NULL DEFAULT 'opaque';
  29. ALTER TABLE oauth_clients
  30. ADD CONSTRAINT ck_oauth_clients_access_token_format
  31. CHECK (access_token_format IN ('opaque', 'jwt'));