Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add quota guard for subject tokens #6205

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading