Skip to content

Commit 221c97f

Browse files
committed
fix(backend): Fix attributeMapping field in SamlConnectionAPI params
1 parent b9f32e0 commit 221c97f

File tree

4 files changed

+160
-8
lines changed

4 files changed

+160
-8
lines changed

.changeset/twelve-sides-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/backend': patch
3+
---
4+
5+
Fix `attributeMapping` field in the `CreateSamlConnectionParams` and `UpdateSamlConnectionParams` types.

packages/backend/src/api/__tests__/SamlConnectionApi.test.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,150 @@ describe('SamlConnectionAPI', () => {
7373
expect(response.totalCount).toBe(1);
7474
});
7575
});
76+
77+
describe('createSamlConnection', () => {
78+
it('successfully creates a SAML connection', async () => {
79+
const mockSamlConnectionResponse = {
80+
object: 'saml_connection',
81+
id: 'samlc_123',
82+
name: 'Test Connection',
83+
provider: 'saml_custom',
84+
domain: 'test.example.com',
85+
organization_id: 'org_123',
86+
created_at: 1672531200000,
87+
updated_at: 1672531200000,
88+
active: true,
89+
sync_user_attributes: false,
90+
allow_subdomains: false,
91+
allow_idp_initiated: false,
92+
idp_entity_id: 'entity_123',
93+
idp_sso_url: 'https://idp.example.com/sso',
94+
idp_certificate: 'cert_data',
95+
idp_metadata_url: null,
96+
idp_metadata: null,
97+
attribute_mapping: {
98+
user_id: 'userId',
99+
email_address: 'email',
100+
first_name: 'firstName',
101+
last_name: 'lastName',
102+
},
103+
};
104+
105+
server.use(
106+
http.post(
107+
'https://api.clerk.test/v1/saml_connections',
108+
validateHeaders(async ({ request }) => {
109+
const body = await request.json();
110+
111+
console.log(body);
112+
expect(body).toEqual({
113+
name: 'Test Connection',
114+
provider: 'saml_custom',
115+
domain: 'test.example.com',
116+
attribute_mapping: {
117+
user_id: 'userId',
118+
email_address: 'email',
119+
first_name: 'firstName',
120+
last_name: 'lastName',
121+
},
122+
});
123+
return HttpResponse.json(mockSamlConnectionResponse);
124+
}),
125+
),
126+
);
127+
128+
const response = await apiClient.samlConnections.createSamlConnection({
129+
name: 'Test Connection',
130+
provider: 'saml_custom',
131+
domain: 'test.example.com',
132+
attributeMapping: {
133+
user_id: 'userId',
134+
email_address: 'email',
135+
first_name: 'firstName',
136+
last_name: 'lastName',
137+
},
138+
});
139+
140+
expect(response.id).toBe('samlc_123');
141+
expect(response.name).toBe('Test Connection');
142+
expect(response.organizationId).toBe('org_123');
143+
});
144+
});
145+
146+
describe('updateSamlConnection', () => {
147+
it('successfully updates a SAML connection', async () => {
148+
const mockSamlConnectionResponse = {
149+
object: 'saml_connection',
150+
id: 'samlc_123',
151+
name: 'Test Connection',
152+
provider: 'saml_custom',
153+
domain: 'test.example.com',
154+
organization_id: 'org_123',
155+
created_at: 1672531200000,
156+
updated_at: 1672531200000,
157+
active: true,
158+
sync_user_attributes: false,
159+
allow_subdomains: false,
160+
allow_idp_initiated: false,
161+
idp_entity_id: 'entity_123',
162+
idp_sso_url: 'https://idp.example.com/sso',
163+
idp_certificate: 'cert_data',
164+
idp_metadata_url: null,
165+
idp_metadata: null,
166+
attribute_mapping: {
167+
user_id: 'userId',
168+
email_address: 'email',
169+
first_name: 'firstName',
170+
last_name: 'lastName',
171+
},
172+
};
173+
174+
server.use(
175+
http.patch(
176+
'https://api.clerk.test/v1/saml_connections/samlc_123',
177+
validateHeaders(async ({ request }) => {
178+
const body = await request.json();
179+
180+
console.log(body);
181+
expect(body).toEqual({
182+
name: 'Test Connection',
183+
provider: 'saml_custom',
184+
domain: 'test.example.com',
185+
organization_id: 'org_123',
186+
idp_entity_id: 'entity_123',
187+
idp_sso_url: 'https://idp.example.com/sso',
188+
idp_certificate: 'cert_data',
189+
attribute_mapping: {
190+
user_id: 'userId',
191+
email_address: 'email',
192+
first_name: 'firstName',
193+
last_name: 'lastName',
194+
},
195+
});
196+
return HttpResponse.json(mockSamlConnectionResponse);
197+
}),
198+
),
199+
);
200+
201+
const response = await apiClient.samlConnections.updateSamlConnection('samlc_123', {
202+
name: 'Test Connection',
203+
provider: 'saml_custom',
204+
domain: 'test.example.com',
205+
organizationId: 'org_123',
206+
idpEntityId: 'entity_123',
207+
idpSsoUrl: 'https://idp.example.com/sso',
208+
idpCertificate: 'cert_data',
209+
attributeMapping: {
210+
user_id: 'userId',
211+
email_address: 'email',
212+
first_name: 'firstName',
213+
last_name: 'lastName',
214+
},
215+
});
216+
217+
expect(response.id).toBe('samlc_123');
218+
expect(response.name).toBe('Test Connection');
219+
expect(response.organizationId).toBe('org_123');
220+
});
221+
});
76222
});

packages/backend/src/api/endpoints/SamlConnectionApi.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ type CreateSamlConnectionParams = {
3939
idpMetadataUrl?: string;
4040
idpMetadata?: string;
4141
attributeMapping?: {
42-
emailAddress?: string;
43-
firstName?: string;
44-
lastName?: string;
45-
userId?: string;
42+
email_address?: string;
43+
first_name?: string;
44+
last_name?: string;
45+
user_id?: string;
4646
};
4747
};
4848

@@ -57,10 +57,10 @@ type UpdateSamlConnectionParams = {
5757
idpMetadataUrl?: string;
5858
idpMetadata?: string;
5959
attributeMapping?: {
60-
emailAddress?: string;
61-
firstName?: string;
62-
lastName?: string;
63-
userId?: string;
60+
email_address?: string;
61+
first_name?: string;
62+
last_name?: string;
63+
user_id?: string;
6464
};
6565
active?: boolean;
6666
syncUserAttributes?: boolean;
@@ -102,6 +102,7 @@ export class SamlConnectionAPI extends AbstractAPI {
102102
bodyParams: params,
103103
});
104104
}
105+
105106
public async deleteSamlConnection(samlConnectionId: string) {
106107
this.requireId(samlConnectionId);
107108
return this.request<SamlConnection>({

packages/remix/tsup.config.bundled_dxbu48uu2wf.mjs

Whitespace-only changes.

0 commit comments

Comments
 (0)