Skip to content

feat(core, schemas): list user grants by userId#8482

Open
simeng-li wants to merge 4 commits intomasterfrom
simeng-log-13048-core-revoke-third-party-app-grant-by-appid
Open

feat(core, schemas): list user grants by userId#8482
simeng-li wants to merge 4 commits intomasterfrom
simeng-log-13048-core-revoke-third-party-app-grant-by-appid

Conversation

@simeng-li
Copy link
Contributor

Summary

Introduce a new GET /users/:userId/grants endpoint to support listing user grants by userId. With an optional filter parameter appType, allow filtering the grants by application type.

Testing

Integration tests added.

Checklist

  • .changeset
  • unit tests
  • integration tests
  • necessary TSDoc comments

@simeng-li simeng-li requested review from a team and Copilot March 13, 2026 09:03
@github-actions github-actions bot added the feature Cool stuff label Mar 13, 2026
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

COMPARE TO master

Total Size Diff ⚠️ 📈 +12.25 KB

Diff by File
Name Diff
packages/core/src/mocks/oidc-grant.ts 📈 +420 Bytes
packages/core/src/libraries/session.ts 📈 +915 Bytes
packages/core/src/queries/oidc-model-instance.test.ts 📈 +3.13 KB
packages/core/src/queries/oidc-model-instance.ts 📈 +2.07 KB
packages/core/src/routes/admin-user/session.openapi.json 📈 +856 Bytes
packages/core/src/routes/admin-user/session.ts 📈 +794 Bytes
packages/integration-tests/src/api/admin-user.ts 📈 +356 Bytes
packages/integration-tests/src/tests/api/sessions/index.test.ts 📈 +1.97 KB
packages/schemas/alterations/next-1772621060-add-oidc-model-instances-grant-account-id-index.ts 📈 +902 Bytes
packages/schemas/src/types/user-sessions.ts 📈 +779 Bytes
packages/schemas/tables/oidc_model_instances.sql 📈 +177 Bytes

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a management (dev-feature) API to list a user’s active OIDC application grants, with optional filtering by first-party vs third-party applications, and improves query performance via a dedicated index.

Changes:

  • Add GET /users/:userId/grants (and OpenAPI doc) returning non-expired grants with optional appType filter.
  • Add DB index for Grant lookups by (payload->>'accountId') + expires_at (including an alteration script for concurrent creation).
  • Add schema guards/types and integration/unit test coverage for the new query/endpoint.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/schemas/tables/oidc_model_instances.sql Adds a baseline schema index for Grant lookups by accountId/expiry.
packages/schemas/alterations/next-1772621060-add-oidc-model-instances-grant-account-id-index.ts Adds concurrent migration to create/drop the new index safely in existing DBs.
packages/schemas/src/types/user-sessions.ts Introduces Zod guards/types for “user application grant” API responses.
packages/core/src/queries/oidc-model-instance.ts Adds query to fetch active Grant instances joined to Applications (supports appType filtering).
packages/core/src/queries/oidc-model-instance.test.ts Adds unit tests asserting SQL generation and parameters for the new query.
packages/core/src/libraries/session.ts Adds formatting/validation and library method to expose active grants to routes.
packages/core/src/routes/admin-user/session.ts Adds the new admin-user grants route with request/response guards.
packages/core/src/routes/admin-user/session.openapi.json Documents the new endpoint and its appType query parameter.
packages/integration-tests/src/api/admin-user.ts Adds an integration-test API client helper for GET /users/:userId/grants.
packages/integration-tests/src/tests/api/sessions/index.test.ts Adds an integration test validating grant retrieval and appType filtering.
packages/core/src/mocks/oidc-grant.ts Adds a test helper to mock Grant instances in query unit tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

export type QueryResult = Pick<OidcModelInstance, 'payload' | 'consumedAt'>;

const { table, fields } = convertToIdentifiers(OidcModelInstances);
const { table: applicationTable, fields: applicationFields } = convertToIdentifiers(Applications);
@simeng-li simeng-li force-pushed the simeng-log-13048-core-revoke-third-party-app-grant-by-appid branch from d1a7305 to c4d7590 Compare March 16, 2026 02:34
@github-actions github-actions bot added size/l and removed size/l labels Mar 16, 2026
@simeng-li simeng-li changed the title feat(core): list user grants by userId feat(core, schemas): list user grants by userId Mar 17, 2026
@github-actions github-actions bot added size/l and removed size/l labels Mar 17, 2026
list user grants by userId
add dev feature guard
add dev feature guard
remove unused code
@simeng-li simeng-li force-pushed the simeng-log-13048-core-revoke-third-party-app-grant-by-appid branch from c90f242 to adfa59c Compare March 17, 2026 03:12
@github-actions github-actions bot removed the size/l label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants