From 6faece8107d469ac35f0278cbb64132bf87989f4 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 20 Nov 2024 16:26:45 +0800 Subject: [PATCH] chore: update saml application configs table schema --- ...4029-add-saml-application-configs-table.ts | 3 ++- .../jsonb-types/saml-application-configs.ts | 22 +++++++------------ .../tables/saml_application_configs.sql | 3 ++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/schemas/alterations/next-1731904029-add-saml-application-configs-table.ts b/packages/schemas/alterations/next-1731904029-add-saml-application-configs-table.ts index ebfee24ae..ac9fdd137 100644 --- a/packages/schemas/alterations/next-1731904029-add-saml-application-configs-table.ts +++ b/packages/schemas/alterations/next-1731904029-add-saml-application-configs-table.ts @@ -13,7 +13,8 @@ const alteration: AlterationScript = { tenant_id varchar(21) not null references tenants (id) on update cascade on delete cascade, attribute_mapping jsonb /* @use SamlAttributeMapping */ not null default '{}'::jsonb, - sp_metadata jsonb /* @use SamlSpMetadata */ not null, + entity_id varchar(128), + acs_url jsonb /* @use SamlAcsUrl */, primary key (tenant_id, application_id), constraint application_type check (check_application_type(application_id, 'SAML')) diff --git a/packages/schemas/src/foundations/jsonb-types/saml-application-configs.ts b/packages/schemas/src/foundations/jsonb-types/saml-application-configs.ts index 6767718ab..1139a997a 100644 --- a/packages/schemas/src/foundations/jsonb-types/saml-application-configs.ts +++ b/packages/schemas/src/foundations/jsonb-types/saml-application-configs.ts @@ -7,23 +7,17 @@ export const samlAttributeMappingGuard = z.record( z.string() ) satisfies z.ZodType; +// Only support SP HTTP-POST binding for now. export enum BindingType { POST = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST', - REDIRECT = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', } -export type SamlSpMetadata = { - entityId: string; - acsUrl: { - binding: BindingType; - url: string; - }; +export type SamlAcsUrl = { + binding?: BindingType; + url: string; }; -export const samlSpMetadataGuard = z.object({ - entityId: z.string(), - acsUrl: z.object({ - binding: z.nativeEnum(BindingType), - url: z.string(), - }), -}) satisfies ToZodObject; +export const samlAcsUrlGuard = z.object({ + binding: z.nativeEnum(BindingType).optional().default(BindingType.POST), + url: z.string(), +}) satisfies ToZodObject; diff --git a/packages/schemas/tables/saml_application_configs.sql b/packages/schemas/tables/saml_application_configs.sql index 8905e96ec..7ff2a859b 100644 --- a/packages/schemas/tables/saml_application_configs.sql +++ b/packages/schemas/tables/saml_application_configs.sql @@ -11,7 +11,8 @@ create table saml_application_configs ( tenant_id varchar(21) not null references tenants (id) on update cascade on delete cascade, attribute_mapping jsonb /* @use SamlAttributeMapping */ not null default '{}'::jsonb, - sp_metadata jsonb /* @use SamlSpMetadata */ not null, + entity_id varchar(128), + acs_url jsonb /* @use SamlAcsUrl */, primary key (tenant_id, application_id), constraint application_type check (check_application_type(application_id, 'SAML'))