@workos-inc/node 3.1.1 → 3.2.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/users/interfaces/authenticate-user-with-token-options.interface.d.ts +3 -3
- package/lib/users/interfaces/enroll-user-in-mfa-factor.interface.d.ts +11 -0
- package/lib/users/interfaces/enroll-user-in-mfa-factor.interface.js +2 -0
- package/lib/users/interfaces/index.d.ts +1 -0
- package/lib/users/interfaces/index.js +1 -0
- package/lib/users/serializers/authenticate-user-with-code-options.serializer.d.ts +2 -0
- package/lib/users/serializers/{authenticate-user-with-token-options.serializer.js → authenticate-user-with-code-options.serializer.js} +3 -3
- package/lib/users/serializers/enroll-user-in-mfa-factor-options.serializer.d.ts +2 -0
- package/lib/users/serializers/enroll-user-in-mfa-factor-options.serializer.js +9 -0
- package/lib/users/serializers/index.d.ts +2 -2
- package/lib/users/serializers/index.js +2 -2
- package/lib/users/users.d.ts +7 -2
- package/lib/users/users.js +13 -2
- package/lib/users/users.spec.js +63 -2
- package/lib/workos.js +1 -1
- package/package.json +1 -1
- package/lib/users/serializers/authenticate-user-with-token-options.serializer.d.ts +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AuthenticateUserWithCodeOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
code: string;
|
|
4
4
|
expiresIn?: number;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface AuthenticateUserWithCodeCredentials {
|
|
7
7
|
clientSecret: string | undefined;
|
|
8
8
|
}
|
|
9
|
-
export interface
|
|
9
|
+
export interface SerializedAuthenticateUserWithCodeOptions {
|
|
10
10
|
grant_type: 'authorization_code';
|
|
11
11
|
client_id: string;
|
|
12
12
|
client_secret: string | undefined;
|
|
@@ -7,6 +7,7 @@ export * from './complete-password-reset-options.interface';
|
|
|
7
7
|
export * from './create-email-verification-challenge-options.interface';
|
|
8
8
|
export * from './create-password-reset-challenge-options.interface';
|
|
9
9
|
export * from './create-user-options.interface';
|
|
10
|
+
export * from './enroll-user-in-mfa-factor.interface';
|
|
10
11
|
export * from './list-users-options.interface';
|
|
11
12
|
export * from './magic-auth-challenge.interface';
|
|
12
13
|
export * from './remove-user-from-organization-options.interface';
|
|
@@ -23,6 +23,7 @@ __exportStar(require("./complete-password-reset-options.interface"), exports);
|
|
|
23
23
|
__exportStar(require("./create-email-verification-challenge-options.interface"), exports);
|
|
24
24
|
__exportStar(require("./create-password-reset-challenge-options.interface"), exports);
|
|
25
25
|
__exportStar(require("./create-user-options.interface"), exports);
|
|
26
|
+
__exportStar(require("./enroll-user-in-mfa-factor.interface"), exports);
|
|
26
27
|
__exportStar(require("./list-users-options.interface"), exports);
|
|
27
28
|
__exportStar(require("./magic-auth-challenge.interface"), exports);
|
|
28
29
|
__exportStar(require("./remove-user-from-organization-options.interface"), exports);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithCodeCredentials, AuthenticateUserWithCodeOptions, SerializedAuthenticateUserWithCodeOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateUserWithCodeOptions: (options: AuthenticateUserWithCodeOptions & AuthenticateUserWithCodeCredentials) => SerializedAuthenticateUserWithCodeOptions;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.serializeAuthenticateUserWithCodeOptions = void 0;
|
|
4
|
+
const serializeAuthenticateUserWithCodeOptions = (options) => ({
|
|
5
5
|
grant_type: 'authorization_code',
|
|
6
6
|
client_id: options.clientId,
|
|
7
7
|
client_secret: options.clientSecret,
|
|
8
8
|
code: options.code,
|
|
9
9
|
expires_in: options.expiresIn,
|
|
10
10
|
});
|
|
11
|
-
exports.
|
|
11
|
+
exports.serializeAuthenticateUserWithCodeOptions = serializeAuthenticateUserWithCodeOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeEnrollUserInMfaFactorOptions = void 0;
|
|
4
|
+
const serializeEnrollUserInMfaFactorOptions = (options) => ({
|
|
5
|
+
type: options.type,
|
|
6
|
+
totp_issuer: options.totpIssuer,
|
|
7
|
+
totp_user: options.totpUser,
|
|
8
|
+
});
|
|
9
|
+
exports.serializeEnrollUserInMfaFactorOptions = serializeEnrollUserInMfaFactorOptions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
export * from './authenticate-user-with-code-options.serializer';
|
|
1
2
|
export * from './authenticate-user-with-magic-auth-options.serializer';
|
|
2
3
|
export * from './authenticate-user-with-password-options.serializer';
|
|
3
|
-
export * from './authenticate-user-with-token-options.serializer';
|
|
4
4
|
export * from './authentication-response.serializer';
|
|
5
5
|
export * from './complete-password-reset-options.serializer';
|
|
6
6
|
export * from './create-email-verification-challenge.serializer';
|
|
@@ -9,7 +9,7 @@ export * from './create-user-options.serializer';
|
|
|
9
9
|
export * from './revoke-session-options.serializer';
|
|
10
10
|
export * from './send-magic-auth-code-options.serializer';
|
|
11
11
|
export * from './session.serializer';
|
|
12
|
-
export * from './update-user-password-options.serializer';
|
|
13
12
|
export * from './update-user-options.serializer';
|
|
13
|
+
export * from './update-user-password-options.serializer';
|
|
14
14
|
export * from './user.serializer';
|
|
15
15
|
export * from './verify-session.serializer';
|
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./authenticate-user-with-code-options.serializer"), exports);
|
|
17
18
|
__exportStar(require("./authenticate-user-with-magic-auth-options.serializer"), exports);
|
|
18
19
|
__exportStar(require("./authenticate-user-with-password-options.serializer"), exports);
|
|
19
|
-
__exportStar(require("./authenticate-user-with-token-options.serializer"), exports);
|
|
20
20
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
21
21
|
__exportStar(require("./complete-password-reset-options.serializer"), exports);
|
|
22
22
|
__exportStar(require("./create-email-verification-challenge.serializer"), exports);
|
|
@@ -25,7 +25,7 @@ __exportStar(require("./create-user-options.serializer"), exports);
|
|
|
25
25
|
__exportStar(require("./revoke-session-options.serializer"), exports);
|
|
26
26
|
__exportStar(require("./send-magic-auth-code-options.serializer"), exports);
|
|
27
27
|
__exportStar(require("./session.serializer"), exports);
|
|
28
|
-
__exportStar(require("./update-user-password-options.serializer"), exports);
|
|
29
28
|
__exportStar(require("./update-user-options.serializer"), exports);
|
|
29
|
+
__exportStar(require("./update-user-password-options.serializer"), exports);
|
|
30
30
|
__exportStar(require("./user.serializer"), exports);
|
|
31
31
|
__exportStar(require("./verify-session.serializer"), exports);
|
package/lib/users/users.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AddUserToOrganizationOptions, AuthenticateUserWithMagicAuthOptions, AuthenticateUserWithPasswordOptions,
|
|
3
|
+
import { AddUserToOrganizationOptions, AuthenticateUserWithMagicAuthOptions, AuthenticateUserWithPasswordOptions, AuthenticateUserWithCodeOptions, AuthenticationResponse, CompletePasswordResetOptions, CreateEmailVerificationChallengeOptions, CreateEmailVerificationChallengeResponse, CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreateUserOptions, ListUsersOptions, MagicAuthChallenge, RemoveUserFromOrganizationOptions, RevokeAllSessionsForUserOptions, RevokeSessionOptions, SendMagicAuthCodeOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifySessionOptions, VerifySessionResponse, EnrollUserInMfaFactorOptions } from './interfaces';
|
|
4
|
+
import { Challenge, Factor } from '../mfa/interfaces';
|
|
4
5
|
export declare class Users {
|
|
5
6
|
private readonly workos;
|
|
6
7
|
constructor(workos: WorkOS);
|
|
@@ -9,7 +10,7 @@ export declare class Users {
|
|
|
9
10
|
createUser(payload: CreateUserOptions): Promise<User>;
|
|
10
11
|
authenticateUserWithMagicAuth(payload: AuthenticateUserWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
11
12
|
authenticateUserWithPassword(payload: AuthenticateUserWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
12
|
-
|
|
13
|
+
authenticateUserWithCode(payload: AuthenticateUserWithCodeOptions): Promise<AuthenticationResponse>;
|
|
13
14
|
verifySession(payload: VerifySessionOptions): Promise<VerifySessionResponse>;
|
|
14
15
|
revokeSession(payload: RevokeSessionOptions): Promise<boolean>;
|
|
15
16
|
revokeAllSessionsForUser({ userId, }: RevokeAllSessionsForUserOptions): Promise<boolean>;
|
|
@@ -22,4 +23,8 @@ export declare class Users {
|
|
|
22
23
|
removeUserFromOrganization({ userId, organizationId, }: RemoveUserFromOrganizationOptions): Promise<User>;
|
|
23
24
|
updateUser(payload: UpdateUserOptions): Promise<User>;
|
|
24
25
|
updateUserPassword(payload: UpdateUserPasswordOptions): Promise<User>;
|
|
26
|
+
enrollUserInMfaFactor(payload: EnrollUserInMfaFactorOptions): Promise<{
|
|
27
|
+
authenticationFactor: Factor;
|
|
28
|
+
authenticationChallenge: Challenge;
|
|
29
|
+
}>;
|
|
25
30
|
}
|
package/lib/users/users.js
CHANGED
|
@@ -13,6 +13,8 @@ exports.Users = void 0;
|
|
|
13
13
|
const pagination_1 = require("../common/utils/pagination");
|
|
14
14
|
const serializers_1 = require("./serializers");
|
|
15
15
|
const fetch_and_deserialize_1 = require("../common/utils/fetch-and-deserialize");
|
|
16
|
+
const serializers_2 = require("../mfa/serializers");
|
|
17
|
+
const enroll_user_in_mfa_factor_options_serializer_1 = require("./serializers/enroll-user-in-mfa-factor-options.serializer");
|
|
16
18
|
class Users {
|
|
17
19
|
constructor(workos) {
|
|
18
20
|
this.workos = workos;
|
|
@@ -46,9 +48,9 @@ class Users {
|
|
|
46
48
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
authenticateUserWithCode(payload) {
|
|
50
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.
|
|
53
|
+
const { data } = yield this.workos.post('/users/sessions/token', (0, serializers_1.serializeAuthenticateUserWithCodeOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
52
54
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
53
55
|
});
|
|
54
56
|
}
|
|
@@ -130,5 +132,14 @@ class Users {
|
|
|
130
132
|
return (0, serializers_1.deserializeUser)(data);
|
|
131
133
|
});
|
|
132
134
|
}
|
|
135
|
+
enrollUserInMfaFactor(payload) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
const { data } = yield this.workos.post(`/users/${payload.userId}/auth/factors`, (0, enroll_user_in_mfa_factor_options_serializer_1.serializeEnrollUserInMfaFactorOptions)(payload));
|
|
138
|
+
return {
|
|
139
|
+
authenticationFactor: (0, serializers_2.deserializeFactor)(data.authentication_factor),
|
|
140
|
+
authenticationChallenge: (0, serializers_2.deserializeChallenge)(data.authentication_challenge),
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
133
144
|
}
|
|
134
145
|
exports.Users = Users;
|
package/lib/users/users.spec.js
CHANGED
|
@@ -146,12 +146,12 @@ describe('UserManagement', () => {
|
|
|
146
146
|
});
|
|
147
147
|
}));
|
|
148
148
|
});
|
|
149
|
-
describe('
|
|
149
|
+
describe('authenticateUserWithCode', () => {
|
|
150
150
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
151
151
|
mock
|
|
152
152
|
.onPost('/users/sessions/token')
|
|
153
153
|
.reply(200, { user: user_json_1.default, session: session_json_1.default });
|
|
154
|
-
const resp = yield workos.users.
|
|
154
|
+
const resp = yield workos.users.authenticateUserWithCode({
|
|
155
155
|
clientId: 'proj_whatever',
|
|
156
156
|
code: 'or this',
|
|
157
157
|
expiresIn: 15,
|
|
@@ -375,4 +375,65 @@ describe('UserManagement', () => {
|
|
|
375
375
|
});
|
|
376
376
|
}));
|
|
377
377
|
});
|
|
378
|
+
describe('enrollUserInMfaFactor', () => {
|
|
379
|
+
it('sends an enrollUserInMfaFactor request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
380
|
+
mock.onPost(`/users/${userId}/auth/factors`).reply(200, {
|
|
381
|
+
authentication_factor: {
|
|
382
|
+
object: 'authentication_factor',
|
|
383
|
+
id: 'auth_factor_1234',
|
|
384
|
+
created_at: '2022-03-15T20:39:19.892Z',
|
|
385
|
+
updated_at: '2022-03-15T20:39:19.892Z',
|
|
386
|
+
type: 'totp',
|
|
387
|
+
totp: {
|
|
388
|
+
issuer: 'WorkOS',
|
|
389
|
+
qr_code: 'qr-code-test',
|
|
390
|
+
secret: 'secret-test',
|
|
391
|
+
uri: 'uri-test',
|
|
392
|
+
user: 'some_user',
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
authentication_challenge: {
|
|
396
|
+
object: 'authentication_challenge',
|
|
397
|
+
id: 'auth_challenge_1234',
|
|
398
|
+
created_at: '2022-03-15T20:39:19.892Z',
|
|
399
|
+
updated_at: '2022-03-15T20:39:19.892Z',
|
|
400
|
+
expires_at: '2022-03-15T21:39:19.892Z',
|
|
401
|
+
code: '12345',
|
|
402
|
+
authentication_factor_id: 'auth_factor_1234',
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
const resp = yield workos.users.enrollUserInMfaFactor({
|
|
406
|
+
userId,
|
|
407
|
+
type: 'totp',
|
|
408
|
+
totpIssuer: 'WorkOS',
|
|
409
|
+
totpUser: 'some_user',
|
|
410
|
+
});
|
|
411
|
+
expect(mock.history.post[0].url).toEqual(`/users/${userId}/auth/factors`);
|
|
412
|
+
expect(resp).toMatchObject({
|
|
413
|
+
authenticationFactor: {
|
|
414
|
+
object: 'authentication_factor',
|
|
415
|
+
id: 'auth_factor_1234',
|
|
416
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
417
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
418
|
+
type: 'totp',
|
|
419
|
+
totp: {
|
|
420
|
+
issuer: 'WorkOS',
|
|
421
|
+
qrCode: 'qr-code-test',
|
|
422
|
+
secret: 'secret-test',
|
|
423
|
+
uri: 'uri-test',
|
|
424
|
+
user: 'some_user',
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
authenticationChallenge: {
|
|
428
|
+
object: 'authentication_challenge',
|
|
429
|
+
id: 'auth_challenge_1234',
|
|
430
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
431
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
432
|
+
expiresAt: '2022-03-15T21:39:19.892Z',
|
|
433
|
+
code: '12345',
|
|
434
|
+
authenticationFactorId: 'auth_factor_1234',
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
}));
|
|
438
|
+
});
|
|
378
439
|
});
|
package/lib/workos.js
CHANGED
|
@@ -27,7 +27,7 @@ const mfa_1 = require("./mfa/mfa");
|
|
|
27
27
|
const audit_logs_1 = require("./audit-logs/audit-logs");
|
|
28
28
|
const users_1 = require("./users/users");
|
|
29
29
|
const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
|
|
30
|
-
const VERSION = '3.
|
|
30
|
+
const VERSION = '3.2.0';
|
|
31
31
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
32
|
class WorkOS {
|
|
33
33
|
constructor(key, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AuthenticateUserWithTokenCredentials, AuthenticateUserWithTokenOptions, SerializedAuthenticateUserWithTokenOptions } from '../interfaces';
|
|
2
|
-
export declare const serializeAuthenticateUserWithTokenOptions: (options: AuthenticateUserWithTokenOptions & AuthenticateUserWithTokenCredentials) => SerializedAuthenticateUserWithTokenOptions;
|