Skip to content

Commit f77e3b9

Browse files
authored
feat(core,schemas): add webauthn related origins to account center (#7422)
1 parent 5f9bbce commit f77e3b9

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

packages/core/src/routes/account-center/index.openapi.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
},
3232
"fields": {
3333
"description": "The fields settings for the account API."
34+
},
35+
"webauthnRelatedOrigins": {
36+
"description": "The allowed domains for webauthn."
3437
}
3538
}
3639
}

packages/core/src/routes/account-center/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { AccountCenters, accountCenterFieldControlGuard } from '@logto/schemas';
1+
import {
2+
AccountCenters,
3+
accountCenterFieldControlGuard,
4+
webauthnRelatedOriginsGuard,
5+
} from '@logto/schemas';
6+
import { deduplicate } from '@silverhand/essentials';
27
import { z } from 'zod';
38

49
import koaGuard from '#src/middleware/koa-guard.js';
@@ -29,18 +34,23 @@ export default function accountCentersRoutes<T extends ManagementApiRouter>(
2934
body: z.object({
3035
enabled: z.boolean().optional(),
3136
fields: accountCenterFieldControlGuard.optional(),
37+
webauthnRelatedOrigins: webauthnRelatedOriginsGuard.optional(),
3238
}),
3339
response: AccountCenters.guard,
3440
status: [200],
3541
}),
3642

3743
async (ctx, next) => {
38-
const { enabled, fields } = ctx.guard.body;
44+
const { enabled, fields, webauthnRelatedOrigins } = ctx.guard.body;
45+
3946
// Make sure the account center exists
4047
await findDefaultAccountCenter();
4148
const updatedAccountCenter = await updateDefaultAccountCenter({
4249
enabled,
4350
fields,
51+
webauthnRelatedOrigins: webauthnRelatedOrigins
52+
? deduplicate(webauthnRelatedOrigins)
53+
: undefined,
4454
});
4555

4656
ctx.body = updatedAccountCenter;

packages/integration-tests/src/tests/api/account-center.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('account center', () => {
2323
fields: {
2424
username: AccountCenterControlValue.Edit,
2525
},
26+
webauthnRelatedOrigins: ['https://example.com'],
2627
};
2728

2829
const updatedAccountCenter = await updateAccountCenter(accountCenter);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { sql } from '@silverhand/slonik';
2+
3+
import type { AlterationScript } from '../lib/types/alteration.js';
4+
5+
const alteration: AlterationScript = {
6+
up: async (pool) => {
7+
await pool.query(sql`
8+
alter table account_centers
9+
add column webauthn_related_origins jsonb not null default '[]'::jsonb;
10+
`);
11+
},
12+
down: async (pool) => {
13+
await pool.query(sql`
14+
alter table account_centers
15+
drop column webauthn_related_origins;
16+
`);
17+
},
18+
};
19+
20+
export default alteration;

packages/schemas/src/foundations/jsonb-types/account-centers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ export const accountCenterFieldControlGuard = z
2727
.partial();
2828

2929
export type AccountCenterFieldControl = z.infer<typeof accountCenterFieldControlGuard>;
30+
31+
export const webauthnRelatedOriginsGuard = z.array(z.string());
32+
33+
export type WebauthnRelatedOrigins = z.infer<typeof webauthnRelatedOriginsGuard>;

packages/schemas/tables/account_centers.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ create table account_centers (
66
enabled boolean not null default false,
77
/** Control each fields */
88
fields jsonb /* @use AccountCenterFieldControl */ not null default '{}'::jsonb,
9+
webauthn_related_origins jsonb /* @use WebauthnRelatedOrigins */ not null default '[]'::jsonb,
910
primary key (tenant_id, id)
1011
);

0 commit comments

Comments
 (0)