Skip to content

Commit c99d908

Browse files
authored
Migrate SSO to camelCased (#793)
## Description * Part of a wider initiative to migrate our Node SDK to camel case for the 3.0.0 release. * Migrates the Single Sign-On module to camel case. ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent 5d53971 commit c99d908

File tree

12 files changed

+180
-49
lines changed

12 files changed

+180
-49
lines changed

src/sso/__snapshots__/sso.spec.ts.snap

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ exports[`SSO SSO getProfileAndToken with all information provided sends a reques
2727

2828
exports[`SSO SSO getProfileAndToken with all information provided sends a request to the WorkOS api for a profile 3`] = `
2929
{
30-
"connection_id": "conn_123",
31-
"connection_type": "OktaSAML",
30+
"connectionId": "conn_123",
31+
"connectionType": "OktaSAML",
3232
"email": "[email protected]",
33-
"first_name": "foo",
33+
"firstName": "foo",
3434
"groups": [
3535
"Admins",
3636
"Developers",
3737
],
3838
"id": "prof_123",
39-
"idp_id": "123",
40-
"last_name": "bar",
41-
"organization_id": "org_123",
42-
"raw_attributes": {
39+
"idpId": "123",
40+
"lastName": "bar",
41+
"organizationId": "org_123",
42+
"rawAttributes": {
4343
"email": "[email protected]",
4444
"first_name": "foo",
4545
"groups": [
@@ -64,15 +64,16 @@ exports[`SSO SSO getProfileAndToken without a groups attribute sends a request t
6464

6565
exports[`SSO SSO getProfileAndToken without a groups attribute sends a request to the WorkOS api for a profile 3`] = `
6666
{
67-
"connection_id": "conn_123",
68-
"connection_type": "OktaSAML",
67+
"connectionId": "conn_123",
68+
"connectionType": "OktaSAML",
6969
"email": "[email protected]",
70-
"first_name": "foo",
70+
"firstName": "foo",
71+
"groups": undefined,
7172
"id": "prof_123",
72-
"idp_id": "123",
73-
"last_name": "bar",
74-
"organization_id": "org_123",
75-
"raw_attributes": {
73+
"idpId": "123",
74+
"lastName": "bar",
75+
"organizationId": "org_123",
76+
"rawAttributes": {
7677
"email": "[email protected]",
7778
"first_name": "foo",
7879
"last_name": "bar",

src/sso/interfaces/connection.interface.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ export interface ConnectionDomain {
77
}
88

99
export interface Connection {
10+
object: 'connection';
11+
id: string;
12+
organizationId?: string;
13+
name: string;
14+
/**
15+
* @deprecated The connectionType parameter has been deprecated. Please use type.
16+
*/
17+
connectionType: ConnectionType;
18+
state: 'draft' | 'active' | 'inactive' | 'validating';
19+
/**
20+
* @deprecated The status parameter has been deprecated. Please use state.
21+
*/
22+
status: 'linked' | 'unlinked';
23+
domains: ConnectionDomain[];
24+
type: ConnectionType;
25+
createdAt: string;
26+
updatedAt: string;
27+
}
28+
29+
export interface ConnectionResponse {
1030
object: 'connection';
1131
id: string;
1232
organization_id?: string;

src/sso/interfaces/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from './authorization-url-options.interface';
22
export * from './connection-type.enum';
33
export * from './connection.interface';
4+
export * from './get-profile-options.interface';
45
export * from './get-profile-and-token-options.interface';
6+
export * from './list-connections-options.interface';
57
export * from './profile-and-token.interface';
68
export * from './profile.interface';

src/sso/interfaces/list-connections-options.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { PaginationOptions } from '../../common/interfaces/pagination-options.in
22
import { ConnectionType } from './connection-type.enum';
33

44
export interface ListConnectionsOptions extends PaginationOptions {
5+
connectionType?: ConnectionType;
6+
domain?: string;
7+
organizationId?: string;
8+
}
9+
10+
export interface SerializedListConnectionsOptions extends PaginationOptions {
511
connection_type?: ConnectionType;
612
domain?: string;
713
organization_id?: string;
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { Profile } from './profile.interface';
1+
import { Profile, ProfileResponse } from './profile.interface';
22

33
export interface ProfileAndToken {
4-
access_token: string;
4+
accessToken: string;
55
profile: Profile;
66
}
7+
8+
export interface ProfileAndTokenResponse {
9+
access_token: string;
10+
profile: ProfileResponse;
11+
}

src/sso/interfaces/profile.interface.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { ConnectionType } from './connection-type.enum';
22

33
export interface Profile {
4+
id: string;
5+
idpId: string;
6+
organizationId?: string;
7+
connectionId: string;
8+
connectionType: ConnectionType;
9+
email: string;
10+
firstName?: string;
11+
lastName?: string;
12+
groups?: string[];
13+
rawAttributes?: { [key: string]: any };
14+
}
15+
16+
export interface ProfileResponse {
417
id: string;
518
idp_id: string;
619
organization_id?: string;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Connection, ConnectionResponse } from '../interfaces';
2+
3+
export const deserializeConnection = (
4+
connection: ConnectionResponse,
5+
): Connection => ({
6+
object: connection.object,
7+
id: connection.id,
8+
organizationId: connection.organization_id,
9+
name: connection.name,
10+
connectionType: connection.connection_type,
11+
type: connection.connection_type,
12+
state: connection.state,
13+
status: connection.status,
14+
domains: connection.domains,
15+
createdAt: connection.created_at,
16+
updatedAt: connection.updated_at,
17+
});

src/sso/serializers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './connection.serializer';
2+
export * from './profile-and-token.serializer';
3+
export * from './profile.serializer';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ProfileAndToken, ProfileAndTokenResponse } from '../interfaces';
2+
import { deserializeProfile } from './profile.serializer';
3+
4+
export const deserializeProfileAndToken = (
5+
profileAndToken: ProfileAndTokenResponse,
6+
): ProfileAndToken => ({
7+
accessToken: profileAndToken.access_token,
8+
profile: deserializeProfile(profileAndToken.profile),
9+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Profile, ProfileResponse } from '../interfaces';
2+
3+
export const deserializeProfile = (profile: ProfileResponse): Profile => ({
4+
id: profile.id,
5+
idpId: profile.idp_id,
6+
organizationId: profile.organization_id,
7+
connectionId: profile.connection_id,
8+
connectionType: profile.connection_type,
9+
email: profile.email,
10+
firstName: profile.first_name,
11+
lastName: profile.last_name,
12+
groups: profile.groups,
13+
rawAttributes: profile.raw_attributes,
14+
});

0 commit comments

Comments
 (0)