Skip to content

feat: authorize access policy + persisted per-scope consent - #3246

Merged
tada5hi merged 6 commits into
masterfrom
feat/roadmap-wave4-authorize
Jul 14, 2026
Merged

tada5hi merged 6 commits into
masterfrom
feat/roadmap-wave4-authorize

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Roadmap Wave 4 — the authorize-path product pair (Authentik-parity plans 052 + 055). Stacked on #3245 (the two policy-evaluation fixes it depends on); rebase onto master once #3245 merges, or merge #3245 first.

Four commits: prerequisite threading → application access policy (052) → persisted per-scope consent (055) → adversarial-review hardening.

052 — application access policy

Optional Client.access_policy_id (FK → auth_policies, ON DELETE SET NULL, null = default-allow) gating who may obtain a token for a client, evaluated fail-closed at three legs:

  • /authorize issuance — the last gate before code issuance (after realm → MFA → freshness); denial throws OAuth2AccessDeniedError.
  • federated-IdP callback — mints codes outside authorize(); denial redirects back to the hosted authorize page with error=access_denied.
  • /token code-redemption backstop — catches pre-policy codes / missed mint sites; denial = invalid_grant.

Fail-closed everywhere (unresolvable/dangling policy id, load/eval failure, and a policy-carrying client with no wired evaluator). A verified redirect_uri gets an error=access_denied redirect (RFC 6749 §4.1.2.1); an unverified one renders the kit's interactive denial card (redirectUri/state ride non-enumerable class fields so they never reach the wire body). access_policy_id joins the client self-manage denylist, stays out of the anonymous ClientSummary, and is admin-editable via APolicyPicker. Denials record EventName.AUTHORIZE_FAILED + the now-live authup_authorize_total{outcome="denied"} metric.

Documented boundary: this is admission control — it is not evaluated on the refresh_token grant, so evict an already-admitted identity via session revocation. The gate feeds IDENTITY policy data only (an ATTRIBUTES-type access policy fails closed).

055 — persisted consent (per-scope)

auth_consents stores one row per (client_id, sub, sub_kind, scope token) (4-col unique index, CASCADE FKs, dormant expires_at honored by the covering check) — a deliberate deviation from the plan's merged-string draft that enables partial (per-scope) revoke.

  • Recorded only at POST /authorize approval (after the 052 gate — a denied identity writes nothing), skipping built_in clients, with union/keep semantics (insert missing tokens only; subscriber-preserving per-row saves).
  • A strict lowercase-token-superset covering match lets the kit skip the consent prompt; the covering read is 60s-cached (CachePrefix.CONSENT_COVERING) and invalidated by the new ConsentEntitySubscriber (realtime + audit for free). This makes prompt=none meaningful for non-built_in clients.
  • Self-service CONSENT_READ/CONSENT_DELETE API mirrors sessions (read + delete only), plus a new settings Applications tab with per-scope revoke chips and per-app revoke-all.

Adversarial review hardening (final commit)

A 57-agent review pass fixed before merge:

  • (HIGH) the consent covering probe wasn't subject-scoped — an actor holding CONSENT_READ (admin/realm_admin) opening an authorize flow could auto-consent off another user's stored grant. Now filtered + re-checked by sub/sub_kind, driven off the resolved user (not the token-derived loggedIn), and drops stale in-flight responses across logout/account-switch.
  • (MEDIUM) GET /consents?include=client leaked the full ClientEntity (redirect_uri patterns, grant_types, secret-storage flags, access_policy_id) to self-service users without CLIENT_READ — now a fixed client-summary join.
  • empty / over-long scope-token drift between server and kit (shared CONSENT_SCOPE_MAX_LENGTH).

Each fix has a regression test.

Schema

Two fresh migration pairs — 1783942684249 (access_policy_id) and 1783946622534 (auth_consents) — both round-trip-verified (run → revert-all → re-run) on MySQL and PostgreSQL locally.

Verification

  • Full dependency-ordered build green (22 projects).
  • apps/server-core full suite 1543 green; client-web-kit 129 green; specs/core-kit/i18n (locale-parity) green.
  • check:types clean; eslint clean.

Docs: .agents/architecture.md gains "Application Access Policy" and "OAuth2 Consent" sections and the plan-043 pointer now resolves to the implemented feature.

Summary by CodeRabbit

  • New Features

    • Added an Applications settings page to review granted permissions and revoke individual or all access.
    • Added persisted OAuth consent handling, including automatic approval for previously granted scopes and consent_required for silent requests without consent.
    • Added configurable application access policies with enforcement during authorization, identity-provider sign-in, and token redemption.
    • Added access-policy selection to application forms and consent management APIs.
  • Bug Fixes

    • Improved access-denied handling with safer redirects and clearer authorization error screens.
    • Authorization failures are now recorded consistently for monitoring.

Copilot AI review requested due to automatic review settings July 13, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds OAuth2 application access policies and persisted per-scope consent. Policies are evaluated during authorization, federated callbacks, and token redemption. Consent records gain database persistence, APIs, permission-aware management, authorization-flow recording, covering probes, silent-login handling, and settings-page revocation UI.

Changes

OAuth2 access policy and consent

Layer / File(s) Summary
Consent and client data contracts
apps/server-core/src/adapters/database/..., apps/server-core/src/core/entities/consent/..., packages/core-kit/src/domains/...
Adds Client.access_policy_id, the Consent entity, consent storage migrations, repository/service contracts, and permission constants.
Consent service and management API
apps/server-core/src/app/modules/oauth2/..., apps/server-core/src/adapters/http/controllers/entities/consent/..., packages/core-http-kit/src/domains/entities/consent/...
Persists normalized consent scopes, checks unexpired coverage, exposes consent listing/deletion endpoints, and wires the client API and dependency injection.
Authorization policy enforcement
apps/server-core/src/core/oauth2/access-policy/..., apps/server-core/src/core/oauth2/authorization/..., apps/server-core/src/adapters/http/...
Evaluates client policies fail-closed during interactive authorization, federated IdP callbacks, and authorization-code redemption; adds standardized access-denied errors and redirect handling.
Authorization consent UI
packages/client-web-kit/src/components/workflows/authorize/*, apps/client-web/pages/settings/index/applications.vue, packages/client-web-kit/src/components/entities/client/AClientForm.vue
Probes persisted consent for interactive and prompt=none flows, renders access-denied states, adds policy editing, and provides grouped consent revocation controls.
Validation and supporting coverage
apps/server-core/test/unit/..., packages/client-web-kit/test/unit/..., packages/i18n/src/..., .agents/architecture.md
Adds unit/integration tests, localized strings, OAuth2 scope/error contracts, and architecture documentation for access policies and consent behavior.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant AuthorizePage
  participant AuthorizeController
  participant OAuth2Authorization
  participant AccessPolicyEvaluator
  participant ConsentService
  participant TokenEndpoint

  Browser->>AuthorizePage: Submit authorization request
  AuthorizePage->>AuthorizeController: Confirm request
  AuthorizeController->>OAuth2Authorization: Authorize verified request
  OAuth2Authorization->>AccessPolicyEvaluator: Evaluate client policy
  AccessPolicyEvaluator-->>OAuth2Authorization: Allow or deny
  OAuth2Authorization->>ConsentService: Record granted scopes
  OAuth2Authorization-->>AuthorizeController: Authorization code or access_denied
  Browser->>TokenEndpoint: Redeem authorization code
  TokenEndpoint->>AccessPolicyEvaluator: Re-evaluate client policy
  AccessPolicyEvaluator-->>TokenEndpoint: Allow or invalid_grant
Loading

Possibly related PRs

  • authup/authup#3194 — Both changes use redirectUriVerified to control OAuth2 denial redirects.
  • authup/authup#3203 — Both modify hosted authorize handling for prompt=none and consent-related redirects.
  • authup/authup#3227 — Both modify the authorization-code grant’s request-time gating flow.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the two main changes: authorization access-policy enforcement and persisted per-scope consent.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/roadmap-wave4-authorize

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3246

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3246

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3246

@authup/access

npm i https://pkg.pr.new/@authup/access@3246

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3246

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3246

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3246

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3246

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3246

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3246

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3246

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3246

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3246

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3246

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3246

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3246

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3246

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3246

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3246

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3246

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3246

commit: ae0a781

Base automatically changed from fix/policy-evaluation to master July 13, 2026 22:01
@tada5hi

tada5hi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@tada5hi tada5hi changed the title feat: authorize access policy + persisted per-scope consent (Wave 4, plans 052 & 055) feat: authorize access policy + persisted per-scope consent Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
apps/server-core/src/core/entities/consent/service.ts (1)

177-183: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Ensure date comparison is robust against driver-level date hydration.

If the underlying database driver (MySQL vs Postgres) hydrates expires_at as a Date object instead of a string, row.expires_at > now (where now is an ISO string) evaluates as Date > string, which results in number > NaN (always false). Converting to a timestamp guarantees correctness regardless of how the database driver returns the value.

♻️ Proposed refactor for robust date comparison
-        const now = new Date().toISOString();
+        const now = Date.now();
 
         return tokens.every((token) => rows.some(
             (row) => row.scope === token &&
-                (row.expires_at === null || row.expires_at > now),
+                (row.expires_at === null || new Date(row.expires_at).getTime() > now),
         ));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/src/core/entities/consent/service.ts` around lines 177 -
183, Update the expiry check in the token validation logic around
findAllBySubjectClient so row.expires_at is normalized to a numeric timestamp
before comparison, supporting both Date and string values. Compare it against
the current time’s numeric timestamp while preserving the null-as-unexpired
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/client-web/pages/settings/index/applications.vue`:
- Around line 1-22: Import VCTimeago from `@vuecs/timeago` and register it in the
defineComponent components option alongside VCButton and VCIcon, ensuring the
existing connected-since template usage resolves correctly.
- Around line 64-87: Update the consent grouping and revoke-all flow around
groupByClient and revokeAll so each client group represents all of that client’s
consents, not only the current page’s props.data. Ensure revoke-all deletes
every consent for the selected client and connected-since uses the earliest
created_at across the complete dataset; obtain the full records through the
existing data-loading mechanism rather than relying solely on the active page.

In `@packages/client-web-kit/test/unit/components/entities/client/form.spec.ts`:
- Around line 177-179: Update the assertion in the client form update-request
test to verify that the request body explicitly contains the access_policy_id
property and that its value is null; do not use nullish coalescing, which also
accepts an omitted property. Keep the existing findUpdateRequest flow unchanged.

---

Nitpick comments:
In `@apps/server-core/src/core/entities/consent/service.ts`:
- Around line 177-183: Update the expiry check in the token validation logic
around findAllBySubjectClient so row.expires_at is normalized to a numeric
timestamp before comparison, supporting both Date and string values. Compare it
against the current time’s numeric timestamp while preserving the
null-as-unexpired behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 580daab3-bfd6-4085-8d2d-570f0d621669

📥 Commits

Reviewing files that changed from the base of the PR and between e4c944a and ad133b6.

📒 Files selected for processing (114)
  • .agents/architecture.md
  • apps/client-web/pages/settings/index.vue
  • apps/client-web/pages/settings/index/applications.vue
  • apps/server-core/src/adapters/database/data-source/options/module.ts
  • apps/server-core/src/adapters/database/domains/client/entity.ts
  • apps/server-core/src/adapters/database/domains/consent/entity.ts
  • apps/server-core/src/adapters/database/domains/consent/index.ts
  • apps/server-core/src/adapters/database/domains/consent/subscriber.ts
  • apps/server-core/src/adapters/database/domains/constants.ts
  • apps/server-core/src/adapters/database/domains/index.ts
  • apps/server-core/src/adapters/database/domains/policy/repository.ts
  • apps/server-core/src/adapters/database/migrations/mysql/1783942684249-Default.ts
  • apps/server-core/src/adapters/database/migrations/mysql/1783946622534-Default.ts
  • apps/server-core/src/adapters/database/migrations/postgres/1783942684249-Default.ts
  • apps/server-core/src/adapters/database/migrations/postgres/1783946622534-Default.ts
  • apps/server-core/src/adapters/http/adapters/oauth2/authorization/module.ts
  • apps/server-core/src/adapters/http/adapters/oauth2/authorization/types.ts
  • apps/server-core/src/adapters/http/adapters/oauth2/grant-types/authorize.ts
  • apps/server-core/src/adapters/http/adapters/oauth2/grant-types/types.ts
  • apps/server-core/src/adapters/http/controllers/entities/consent/index.ts
  • apps/server-core/src/adapters/http/controllers/entities/consent/module.ts
  • apps/server-core/src/adapters/http/controllers/entities/identity-provider/module.ts
  • apps/server-core/src/adapters/http/controllers/entities/identity-provider/types.ts
  • apps/server-core/src/adapters/http/controllers/entities/index.ts
  • apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/authorize/types.ts
  • apps/server-core/src/adapters/http/controllers/workflows/token/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/token/types.ts
  • apps/server-core/src/app/modules/database/repositories/client/repository.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/app/modules/oauth2/constants.ts
  • apps/server-core/src/app/modules/oauth2/module.ts
  • apps/server-core/src/app/modules/oauth2/repositories/consent/index.ts
  • apps/server-core/src/app/modules/oauth2/repositories/consent/repository.ts
  • apps/server-core/src/app/modules/oauth2/repositories/index.ts
  • apps/server-core/src/app/modules/provisioning/sources/default/module.ts
  • apps/server-core/src/core/entities/consent/index.ts
  • apps/server-core/src/core/entities/consent/service.ts
  • apps/server-core/src/core/entities/consent/types.ts
  • apps/server-core/src/core/entities/index.ts
  • apps/server-core/src/core/identity/permission/index.ts
  • apps/server-core/src/core/identity/policy/checker/service.ts
  • apps/server-core/src/core/oauth2/access-policy/index.ts
  • apps/server-core/src/core/oauth2/access-policy/module.ts
  • apps/server-core/src/core/oauth2/access-policy/types.ts
  • apps/server-core/src/core/oauth2/authorization/module.ts
  • apps/server-core/src/core/oauth2/authorization/types.ts
  • apps/server-core/src/core/oauth2/index.ts
  • apps/server-core/test/unit/core/entities/consent/fake-repository.ts
  • apps/server-core/test/unit/core/entities/consent/service.spec.ts
  • apps/server-core/test/unit/core/identity/policy/checker.spec.ts
  • apps/server-core/test/unit/core/oauth2/access-policy/evaluator.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/code-request/verifier/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/client-self-manage.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/client.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/consent.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/authorize-access-policy.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/token/grant-authorize-access-policy.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/token/grant-idp-authorize.spec.ts
  • apps/server-core/test/unit/http/controllers/workflows/ui-pages.spec.ts
  • packages/client-web-kit/src/components/entities/client/AClientForm.vue
  • packages/client-web-kit/src/components/entities/consent/AConsents.ts
  • packages/client-web-kit/src/components/entities/consent/index.ts
  • packages/client-web-kit/src/components/entities/index.ts
  • packages/client-web-kit/src/components/workflows/authorize/Authorize.vue
  • packages/client-web-kit/src/components/workflows/authorize/AuthorizeForm.vue
  • packages/client-web-kit/test/unit/components/entities/client/form.spec.ts
  • packages/client-web-kit/test/unit/components/workflows/authorize-form.spec.ts
  • packages/client-web-kit/test/unit/components/workflows/authorize.spec.ts
  • packages/core-http-kit/src/client/module.ts
  • packages/core-http-kit/src/client/type.ts
  • packages/core-http-kit/src/domains/entities/client/types.ts
  • packages/core-http-kit/src/domains/entities/consent/index.ts
  • packages/core-http-kit/src/domains/entities/consent/module.ts
  • packages/core-http-kit/src/domains/entities/consent/types.ts
  • packages/core-http-kit/src/domains/entities/index.ts
  • packages/core-kit/src/domains/client/entity.ts
  • packages/core-kit/src/domains/client/validator.ts
  • packages/core-kit/src/domains/consent/entity.ts
  • packages/core-kit/src/domains/consent/index.ts
  • packages/core-kit/src/domains/contstants.ts
  • packages/core-kit/src/domains/event/constants.ts
  • packages/core-kit/src/domains/index.ts
  • packages/core-kit/src/domains/permission/constants.ts
  • packages/core-kit/src/domains/types.ts
  • packages/errors/src/constants.ts
  • packages/i18n/src/catalogs/de/app.ts
  • packages/i18n/src/catalogs/de/client.ts
  • packages/i18n/src/catalogs/de/entity.ts
  • packages/i18n/src/catalogs/de/error.ts
  • packages/i18n/src/catalogs/de/field.ts
  • packages/i18n/src/catalogs/en/app.ts
  • packages/i18n/src/catalogs/en/client.ts
  • packages/i18n/src/catalogs/en/entity.ts
  • packages/i18n/src/catalogs/en/error.ts
  • packages/i18n/src/catalogs/en/field.ts
  • packages/i18n/src/catalogs/es/app.ts
  • packages/i18n/src/catalogs/es/client.ts
  • packages/i18n/src/catalogs/es/entity.ts
  • packages/i18n/src/catalogs/es/error.ts
  • packages/i18n/src/catalogs/es/field.ts
  • packages/i18n/src/catalogs/fr/app.ts
  • packages/i18n/src/catalogs/fr/client.ts
  • packages/i18n/src/catalogs/fr/entity.ts
  • packages/i18n/src/catalogs/fr/error.ts
  • packages/i18n/src/catalogs/fr/field.ts
  • packages/i18n/src/constants.ts
  • packages/specs/src/oauth2/check.ts
  • packages/specs/src/oauth2/constants.ts
  • packages/specs/src/oauth2/error/access-denied.ts
  • packages/specs/src/oauth2/error/index.ts
  • packages/specs/test/unit/oauth2/scope.spec.ts

tada5hi added 5 commits July 14, 2026 12:07
The code-request verifier already computes redirectUriVerified but the
HTTP authorizer discarded it. Carry it on OAuth2AuthorizationOptions
(alongside the already-threaded client) so authorize-time denials can
decide between an error redirect (RFC 6749 §4.1.2.1) and an interactive
error. Shared prerequisite of plans 052 and 055.
Optional Client.access_policy_id (FK auth_policies, ON DELETE SET NULL,
null = default-allow) gating who may obtain a token for a client,
evaluated fail-closed by the new OAuth2AccessPolicyEvaluator
(core/oauth2/access-policy) with IDENTITY policy data at three legs:

- OAuth2Authorization.authorizeInner — last gate before code issuance
  (after realm/MFA/freshness); denial throws OAuth2AccessDeniedError
  carrying redirectUri/state as non-enumerable fields iff the
  redirect_uri was pattern-verified
- the federated-IdP callback — redirects back to the hosted authorize
  page with error=access_denied (serve() maps the recognized query
  param onto a neutral hydration error)
- /token code redemption backstop — denial surfaces as invalid_grant

AuthorizeController.confirm answers a verified denial as a 200 { url }
error redirect (RFC 6749 §4.1.2.1); unverified denials render the kit's
localized terminal denial card. access_policy_id joins the client
self-manage denylist, stays out of the anonymous ClientSummary DTO, is
admin-editable via APolicyPicker in AClientForm, and denials record
EventName.AUTHORIZE_FAILED plus the now-live authorize denied metric.
Migration pair 1783942684249 (both dialects, round-trip verified).
…service management

auth_consents stores one row per (client_id, sub, sub_kind, scope token)
(4-col unique, CASCADE FKs, dormant expires_at honored by the covering
check). Recorded exclusively at POST /authorize approval — after the
access-policy gate, never for built_in clients, never on the federated
callback or /token — with union/keep semantics: re-approval only inserts
missing tokens via subscriber-preserving per-row saves.

A stored grant covering the requested tokens (strict lowercase-token
superset via unwrapOAuth2Scope on both sides) lets the kit skip the
consent prompt: Authorize.vue probes the self-scoped consent list
alongside the MFA status fetch, AuthorizeForm auto-submits on covering
consent unless prompt=consent, and the silent branch redirects
consent_required only when no covering consent exists — making
prompt=none meaningful for non-built_in clients.

The covering lookup rides a 60s query cache (CachePrefix.CONSENT_COVERING)
invalidated by the new ConsentEntitySubscriber (realtime + audit for
free). Self-service API mirrors sessions: CONSENT_READ/CONSENT_DELETE,
read+delete only, own rows ungated, per-row realm-match for admins,
plan-039 force-selects. New settings Applications tab groups per-scope
rows by client with chip-level revoke and per-app revoke-all. i18n x4,
typed client.consent API, migration pair 1783946622534 (round-trip
verified on mysql + postgres).
- Consent covering probe (Authorize.vue): scope the probe to the resolved
  user subject (sub + sub_kind) and re-check row.sub in the covering match.
  The server only force-scopes permissionless callers, so an actor holding
  CONSENT_READ (admin/realm_admin) previously received other subjects' rows
  and auto-consented off a stranger's grant. Drive the probe off the
  resolved user id (loggedIn flips before userInfo resolves) and drop any
  in-flight response whose subject is no longer current (logout / account
  switch mid-probe).
- Consent list endpoint: expose only a client summary (id/name/display_name/
  built_in) via a fixed join; drop 'client' from relations.allowed so a raw
  ?include=client cannot leak the full ClientEntity (redirect_uri patterns,
  grant_types, secret-storage flags, access_policy_id) to a self-service
  user without CLIENT_READ.
- Scope-token normalization: drop empty tokens client-side (matching the
  server) so a comma/space-padded scope can still read as covered, and drop
  tokens exceeding CONSENT_SCOPE_MAX_LENGTH (shared entity/service constant)
  so an over-long token can't overflow the column and abort the write loop.
- Docs: scope the access-policy denial event/metric claim to the /authorize
  leg (IdP + token legs are an uninstrumented audit-coverage gap), document
  the refresh-grant admission-control boundary, and record the consent
  Stage-1 orphan-row / summary-join behaviors.

Regression tests: probe subject filter + foreign-subject non-coverage
(kit), client-summary-only leak guard (http), over-long token drop (service).
- Explicitly import + register VCTimeago (convention: new code declares its
  VC* deps rather than relying on the app's global registration).
- Revoke-all now fetches the client's complete consent set before deleting,
  instead of only the current page's rows — per-scope rows can span pages, so
  a page-local revoke-all could leave scopes granted.
- Strengthen the cleared-picker test to assert an explicit access_policy_id:
  null in the body (the nullish-coalescing check also passed on omission).
@tada5hi
tada5hi force-pushed the feat/roadmap-wave4-authorize branch from ad133b6 to dc0ff6a Compare July 14, 2026 10:14
@tada5hi

tada5hi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai pause

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

@tada5hi

tada5hi commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 36 minutes.

…e driver-error guard

- Fold the access_policy_id (052) and auth_consents (055) schema changes
  into the unreleased migration 1783856507391 (both dialects, per the
  fold-per-release convention); drop the two standalone Wave 4 migration
  pairs. Round-trip verified on mysql + postgres.
- auth_consents gains a nullable user_id FK (ON DELETE CASCADE), populated
  when the subject is a user, so deleting a user cascade-drops its consent
  rows (non-user subjects rely on the client/realm cascade). Resolves the
  orphaned-consent-rows limitation from review.
- Relocate the inline duplicate-key check to a reusable
  adapters/database/errors/driver.ts: getDatabaseDriverErrorCode unwraps the
  vendor code from a QueryFailedError (top-level or nested driverError.code),
  isUniqueConstraintDatabaseError matches it across mysql/postgres/sqlite.

Tests: consent user_id population + user-deletion cascade (http), driver
guard unit matrix.
@tada5hi
tada5hi force-pushed the feat/roadmap-wave4-authorize branch from 9721921 to ae0a781 Compare July 14, 2026 10:43
@tada5hi
tada5hi merged commit b4b96c7 into master Jul 14, 2026
11 of 12 checks passed
@tada5hi
tada5hi deleted the feat/roadmap-wave4-authorize branch July 14, 2026 10:53
@github-actions github-actions Bot mentioned this pull request Jul 14, 2026
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.

2 participants