@workos-inc/node 2.1.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/directory-sync/interfaces/group.interface.d.ts +1 -0
- package/lib/directory-sync/interfaces/user.interface.d.ts +1 -0
- package/lib/sso/interfaces/authorization-url-options.interface.d.ts +6 -0
- package/lib/sso/sso.d.ts +1 -1
- package/lib/sso/sso.js +9 -3
- package/lib/sso/sso.spec.js +39 -0
- package/lib/webhooks/interfaces/webhook.interface.d.ts +3 -9
- package/lib/webhooks/webhooks.js +3 -2
- package/lib/webhooks/webhooks.spec.js +1 -1
- package/lib/workos.js +1 -1
- package/package.json +8 -8
|
@@ -2,6 +2,7 @@ import { Group } from './group.interface';
|
|
|
2
2
|
export declare type DefaultCustomAttributes = Record<string, unknown>;
|
|
3
3
|
export interface User<TCustomAttributes extends object = DefaultCustomAttributes> {
|
|
4
4
|
id: string;
|
|
5
|
+
directory_id: string;
|
|
5
6
|
raw_attributes: any;
|
|
6
7
|
custom_attributes: TCustomAttributes;
|
|
7
8
|
idp_id: string;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export interface AuthorizationURLOptions {
|
|
2
2
|
clientID: string;
|
|
3
3
|
connection?: string;
|
|
4
|
+
organization?: string;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Please use `organization` instead.
|
|
7
|
+
*/
|
|
4
8
|
domain?: string;
|
|
9
|
+
domainHint?: string;
|
|
10
|
+
loginHint?: string;
|
|
5
11
|
provider?: string;
|
|
6
12
|
redirectURI: string;
|
|
7
13
|
state?: string;
|
package/lib/sso/sso.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class SSO {
|
|
|
11
11
|
private readonly workos;
|
|
12
12
|
constructor(workos: WorkOS);
|
|
13
13
|
deleteConnection(id: string): Promise<void>;
|
|
14
|
-
getAuthorizationURL({ connection, clientID, domain, provider, redirectURI, state, }: AuthorizationURLOptions): string;
|
|
14
|
+
getAuthorizationURL({ connection, clientID, domain, domainHint, loginHint, organization, provider, redirectURI, state, }: AuthorizationURLOptions): string;
|
|
15
15
|
getConnection(id: string): Promise<Connection>;
|
|
16
16
|
getProfileAndToken({ code, clientID, }: GetProfileAndTokenOptions): Promise<ProfileAndToken>;
|
|
17
17
|
getProfile({ accessToken }: GetProfileOptions): Promise<Profile>;
|
package/lib/sso/sso.js
CHANGED
|
@@ -23,13 +23,19 @@ class SSO {
|
|
|
23
23
|
yield this.workos.delete(`/connections/${id}`);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
getAuthorizationURL({ connection, clientID, domain, provider, redirectURI, state, }) {
|
|
27
|
-
if (!domain && !provider && !connection) {
|
|
28
|
-
throw new Error(`Incomplete arguments. Need to specify either a 'connection', 'domain', or 'provider'.`);
|
|
26
|
+
getAuthorizationURL({ connection, clientID, domain, domainHint, loginHint, organization, provider, redirectURI, state, }) {
|
|
27
|
+
if (!domain && !provider && !connection && !organization) {
|
|
28
|
+
throw new Error(`Incomplete arguments. Need to specify either a 'connection', 'organization', 'domain', or 'provider'.`);
|
|
29
|
+
}
|
|
30
|
+
if (domain) {
|
|
31
|
+
this.workos.emitWarning('The `domain` parameter for `getAuthorizationURL` is deprecated. Please use `organization` instead.');
|
|
29
32
|
}
|
|
30
33
|
const query = query_string_1.default.stringify({
|
|
31
34
|
connection,
|
|
35
|
+
organization,
|
|
32
36
|
domain,
|
|
37
|
+
domain_hint: domainHint,
|
|
38
|
+
login_hint: loginHint,
|
|
33
39
|
provider,
|
|
34
40
|
client_id: clientID,
|
|
35
41
|
redirect_uri: redirectURI,
|
package/lib/sso/sso.spec.js
CHANGED
|
@@ -65,6 +65,19 @@ describe('SSO', () => {
|
|
|
65
65
|
expect(url).toMatchSnapshot();
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
describe('with an `organization`', () => {
|
|
69
|
+
it('generates an authorization URL with the organization', () => {
|
|
70
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
71
|
+
apiHostname: 'api.workos.dev',
|
|
72
|
+
});
|
|
73
|
+
const url = workos.sso.getAuthorizationURL({
|
|
74
|
+
organization: 'organization_123',
|
|
75
|
+
clientID: 'proj_123',
|
|
76
|
+
redirectURI: 'example.com/sso/workos/callback',
|
|
77
|
+
});
|
|
78
|
+
expect(url).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
68
81
|
describe('with a custom api hostname', () => {
|
|
69
82
|
it('generates an authorize url with the custom api hostname', () => {
|
|
70
83
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU', {
|
|
@@ -90,6 +103,32 @@ describe('SSO', () => {
|
|
|
90
103
|
expect(url).toMatchSnapshot();
|
|
91
104
|
});
|
|
92
105
|
});
|
|
106
|
+
describe('with domainHint', () => {
|
|
107
|
+
it('generates an authorize url with the provided domain hint', () => {
|
|
108
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
109
|
+
const url = workos.sso.getAuthorizationURL({
|
|
110
|
+
domainHint: 'lyft.com',
|
|
111
|
+
connection: 'connection_123',
|
|
112
|
+
clientID: 'proj_123',
|
|
113
|
+
redirectURI: 'example.com/sso/workos/callback',
|
|
114
|
+
state: 'custom state',
|
|
115
|
+
});
|
|
116
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&domain_hint=lyft.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom%20state"`);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('with loginHint', () => {
|
|
120
|
+
it('generates an authorize url with the provided login hint', () => {
|
|
121
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
122
|
+
const url = workos.sso.getAuthorizationURL({
|
|
123
|
+
loginHint: 'foo@workos.com',
|
|
124
|
+
connection: 'connection_123',
|
|
125
|
+
clientID: 'proj_123',
|
|
126
|
+
redirectURI: 'example.com/sso/workos/callback',
|
|
127
|
+
state: 'custom state',
|
|
128
|
+
});
|
|
129
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/sso/authorize?client_id=proj_123&connection=connection_123&login_hint=foo%40workos.com&redirect_uri=example.com%2Fsso%2Fworkos%2Fcallback&response_type=code&state=custom%20state"`);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
93
132
|
});
|
|
94
133
|
describe('getProfileAndToken', () => {
|
|
95
134
|
describe('with all information provided', () => {
|
|
@@ -30,21 +30,15 @@ export interface DsyncDeletedWebhook extends WebhookBase {
|
|
|
30
30
|
}
|
|
31
31
|
export interface DsyncGroupCreatedWebhook extends WebhookBase {
|
|
32
32
|
event: 'dsync.group.created';
|
|
33
|
-
data: Group
|
|
34
|
-
directory_id: string;
|
|
35
|
-
};
|
|
33
|
+
data: Group;
|
|
36
34
|
}
|
|
37
35
|
export interface DsyncGroupDeletedWebhook extends WebhookBase {
|
|
38
36
|
event: 'dsync.group.deleted';
|
|
39
|
-
data: Group
|
|
40
|
-
directory_id: string;
|
|
41
|
-
};
|
|
37
|
+
data: Group;
|
|
42
38
|
}
|
|
43
39
|
export interface DsyncGroupUpdatedWebhook extends WebhookBase {
|
|
44
40
|
event: 'dsync.group.updated';
|
|
45
|
-
data: Group
|
|
46
|
-
directory_id: string;
|
|
47
|
-
};
|
|
41
|
+
data: Group;
|
|
48
42
|
}
|
|
49
43
|
export interface DsyncGroupUserAddedWebhook extends WebhookBase {
|
|
50
44
|
event: 'dsync.group.user_added';
|
package/lib/webhooks/webhooks.js
CHANGED
|
@@ -7,13 +7,13 @@ exports.Webhooks = void 0;
|
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const exceptions_1 = require("../common/exceptions");
|
|
9
9
|
class Webhooks {
|
|
10
|
-
constructEvent({ payload, sigHeader, secret, tolerance =
|
|
10
|
+
constructEvent({ payload, sigHeader, secret, tolerance = 180000, }) {
|
|
11
11
|
const options = { payload, sigHeader, secret, tolerance };
|
|
12
12
|
this.verifyHeader(options);
|
|
13
13
|
const webhookPayload = payload;
|
|
14
14
|
return webhookPayload;
|
|
15
15
|
}
|
|
16
|
-
verifyHeader({ payload, sigHeader, secret, tolerance =
|
|
16
|
+
verifyHeader({ payload, sigHeader, secret, tolerance = 180000, }) {
|
|
17
17
|
const [timestamp, signatureHash] = this.getTimestampAndSignatureHash(sigHeader);
|
|
18
18
|
if (!signatureHash || Object.keys(signatureHash).length === 0) {
|
|
19
19
|
throw new exceptions_1.SignatureVerificationException('No signature hash found with expected scheme v1');
|
|
@@ -38,6 +38,7 @@ class Webhooks {
|
|
|
38
38
|
return [timestamp, signatureHash];
|
|
39
39
|
}
|
|
40
40
|
computeSignature(timestamp, payload, secret) {
|
|
41
|
+
payload = JSON.stringify(payload);
|
|
41
42
|
const signedPayload = `${timestamp}.${payload}`;
|
|
42
43
|
const expectedSignature = crypto_1.default
|
|
43
44
|
.createHmac('sha256', secret)
|
|
@@ -19,7 +19,7 @@ describe('Webhooks', () => {
|
|
|
19
19
|
payload = webhook_json_1.default;
|
|
20
20
|
secret = 'secret';
|
|
21
21
|
timestamp = Date.now() * 1000;
|
|
22
|
-
unhashedString = `${timestamp}.${payload}`;
|
|
22
|
+
unhashedString = `${timestamp}.${JSON.stringify(payload)}`;
|
|
23
23
|
signatureHash = crypto_1.default
|
|
24
24
|
.createHmac('sha256', secret)
|
|
25
25
|
.update(unhashedString)
|
package/lib/workos.js
CHANGED
|
@@ -22,7 +22,7 @@ const passwordless_1 = require("./passwordless/passwordless");
|
|
|
22
22
|
const portal_1 = require("./portal/portal");
|
|
23
23
|
const sso_1 = require("./sso/sso");
|
|
24
24
|
const webhooks_1 = require("./webhooks/webhooks");
|
|
25
|
-
const VERSION = '2.
|
|
25
|
+
const VERSION = '2.4.0';
|
|
26
26
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
27
27
|
class WorkOS {
|
|
28
28
|
constructor(key, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.4.0",
|
|
3
3
|
"name": "@workos-inc/node",
|
|
4
4
|
"author": "WorkOS",
|
|
5
5
|
"description": "A Node wrapper for the WorkOS API",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"workos"
|
|
10
10
|
],
|
|
11
11
|
"volta": {
|
|
12
|
-
"node": "14.18.
|
|
12
|
+
"node": "14.18.2",
|
|
13
13
|
"yarn": "1.22.17"
|
|
14
14
|
},
|
|
15
15
|
"main": "lib/index.js",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"query-string": "7.0.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/jest": "27.0.
|
|
43
|
-
"@types/node": "14.
|
|
42
|
+
"@types/jest": "27.0.3",
|
|
43
|
+
"@types/node": "14.18.0",
|
|
44
44
|
"@types/pluralize": "0.0.29",
|
|
45
45
|
"axios-mock-adapter": "1.20.0",
|
|
46
|
-
"jest": "27.
|
|
47
|
-
"prettier": "2.
|
|
46
|
+
"jest": "27.4.5",
|
|
47
|
+
"prettier": "2.5.1",
|
|
48
48
|
"supertest": "6.1.6",
|
|
49
|
-
"ts-jest": "27.
|
|
49
|
+
"ts-jest": "27.1.1",
|
|
50
50
|
"tslint": "6.1.3",
|
|
51
|
-
"typescript": "4.
|
|
51
|
+
"typescript": "4.5.4"
|
|
52
52
|
}
|
|
53
53
|
}
|