Skip to content

Commit

Permalink
feat(core): add quota guard for subject tokens (#6205)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie authored Jul 9, 2024
1 parent dbda05a commit 55ff41e
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 58 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@logto/cloud": "0.2.5-a7eedce",
"@logto/cloud": "0.2.5-3046fa6",
"@silverhand/eslint-config": "6.0.1",
"@silverhand/ts-config": "6.0.0",
"@types/debug": "^4.1.7",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/libraries/quota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const createQuotaLibrary = (
omniSignInEnabled: notNumber, // No limit for now
builtInEmailConnectorEnabled: notNumber, // No limit for now
customJwtEnabled: notNumber, // No limit for now
subjectTokenEnabled: notNumber, // No limit for now
};

const getTenantUsage = async (key: keyof FeatureQuota, queryKey?: string): Promise<number> => {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/routes/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import { object, string } from 'zod';
import { subjectTokenExpiresIn, subjectTokenPrefix } from '#src/constants/index.js';
import { EnvSet } from '#src/env-set/index.js';
import koaGuard from '#src/middleware/koa-guard.js';
import koaQuotaGuard from '#src/middleware/koa-quota-guard.js';

import { type RouterInitArgs, type ManagementApiRouter } from '../types.js';

export default function securityRoutes<T extends ManagementApiRouter>(...args: RouterInitArgs<T>) {
const [router, { queries }] = args;
const [
router,
{
queries,
libraries: { quota },
},
] = args;
const {
subjectTokens: { insertSubjectToken },
} = queries;
Expand All @@ -21,6 +28,7 @@ export default function securityRoutes<T extends ManagementApiRouter>(...args: R

router.post(
'/security/subject-tokens',
koaQuotaGuard({ key: 'subjectTokenEnabled', quota }),
koaGuard({
body: object({
userId: string(),
Expand Down
Loading

0 comments on commit 55ff41e

Please sign in to comment.