@workos-inc/node 3.5.0 → 3.7.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/common/exceptions/generic-server.exception.d.ts +1 -1
- package/lib/common/exceptions/generic-server.exception.js +1 -1
- package/lib/common/exceptions/oauth.exception.d.ts +2 -1
- package/lib/common/exceptions/oauth.exception.js +2 -1
- package/lib/users/fixtures/list-factors.json +23 -0
- package/lib/users/interfaces/{authenticate-user-with-token-options.interface.d.ts → authenticate-with-code-options.interface.d.ts} +6 -4
- package/lib/users/interfaces/{authenticate-user-with-magic-auth-options.interface.d.ts → authenticate-with-magic-auth-options.interface.d.ts} +4 -6
- package/lib/users/interfaces/{authenticate-user-with-password-options.interface.d.ts → authenticate-with-password-options.interface.d.ts} +2 -4
- package/lib/users/interfaces/authenticate-with-totp-options.interface.d.ts +21 -0
- package/lib/users/interfaces/authentication-response.interface.d.ts +0 -3
- package/lib/users/interfaces/{enroll-user-in-mfa-factor.interface.d.ts → enroll-auth-factor.interface.d.ts} +1 -1
- package/lib/users/interfaces/index.d.ts +8 -8
- package/lib/users/interfaces/index.js +8 -8
- package/lib/users/interfaces/list-auth-factors-options.interface.d.ts +4 -0
- package/lib/users/interfaces/reset-password-options.interface.d.ts +8 -0
- package/lib/users/interfaces/send-magic-auth-code-options.interface.d.ts +2 -2
- package/lib/users/interfaces/{create-password-reset-challenge-options.interface.d.ts → send-password-reset-options.interface.d.ts} +4 -4
- package/lib/users/serializers/authenticate-with-code-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-with-code-options.serializer.js +12 -0
- package/lib/users/serializers/authenticate-with-magic-auth-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-with-magic-auth-options.serializer.js +13 -0
- package/lib/users/serializers/authenticate-with-password-options.serializer.d.ts +2 -0
- package/lib/users/serializers/{authenticate-user-with-password-options.serializer.js → authenticate-with-password-options.serializer.js} +3 -4
- package/lib/users/serializers/authenticate-with-totp-options.serializer.d.ts +2 -0
- package/lib/users/serializers/authenticate-with-totp-options.serializer.js +14 -0
- package/lib/users/serializers/authentication-response.serializer.js +0 -2
- package/lib/users/serializers/enroll-auth-factor-options.serializer.d.ts +2 -0
- package/lib/users/serializers/enroll-auth-factor-options.serializer.js +9 -0
- package/lib/users/serializers/index.d.ts +7 -6
- package/lib/users/serializers/index.js +7 -6
- package/lib/users/serializers/reset-password-options.serializer.d.ts +2 -0
- package/lib/users/serializers/reset-password-options.serializer.js +8 -0
- package/lib/users/serializers/send-magic-auth-code-options.serializer.js +1 -1
- package/lib/users/serializers/send-password-reset-email.serializer.d.ts +3 -0
- package/lib/users/serializers/send-password-reset-email.serializer.js +14 -0
- package/lib/users/users.d.ts +14 -8
- package/lib/users/users.js +26 -16
- package/lib/users/users.spec.js +78 -40
- package/lib/workos.js +2 -2
- package/lib/workos.spec.js +1 -1
- package/package.json +1 -1
- package/lib/users/fixtures/session.json +0 -8
- package/lib/users/interfaces/complete-password-reset-options.interface.d.ts +0 -8
- package/lib/users/interfaces/magic-auth-challenge.interface.d.ts +0 -3
- package/lib/users/interfaces/session.interface.d.ts +0 -41
- package/lib/users/serializers/authenticate-user-with-code-options.serializer.d.ts +0 -2
- package/lib/users/serializers/authenticate-user-with-code-options.serializer.js +0 -11
- package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.d.ts +0 -2
- package/lib/users/serializers/authenticate-user-with-magic-auth-options.serializer.js +0 -14
- package/lib/users/serializers/authenticate-user-with-password-options.serializer.d.ts +0 -2
- package/lib/users/serializers/complete-password-reset-options.serializer.d.ts +0 -2
- package/lib/users/serializers/complete-password-reset-options.serializer.js +0 -8
- package/lib/users/serializers/create-password-reset-challenge.serializer.d.ts +0 -3
- package/lib/users/serializers/create-password-reset-challenge.serializer.js +0 -14
- package/lib/users/serializers/enroll-user-in-mfa-factor-options.serializer.d.ts +0 -2
- package/lib/users/serializers/enroll-user-in-mfa-factor-options.serializer.js +0 -9
- package/lib/users/serializers/session.serializer.d.ts +0 -4
- package/lib/users/serializers/session.serializer.js +0 -22
- /package/lib/users/interfaces/{authenticate-user-with-magic-auth-options.interface.js → authenticate-with-code-options.interface.js} +0 -0
- /package/lib/users/interfaces/{authenticate-user-with-password-options.interface.js → authenticate-with-magic-auth-options.interface.js} +0 -0
- /package/lib/users/interfaces/{authenticate-user-with-token-options.interface.js → authenticate-with-password-options.interface.js} +0 -0
- /package/lib/users/interfaces/{complete-password-reset-options.interface.js → authenticate-with-totp-options.interface.js} +0 -0
- /package/lib/users/interfaces/{create-password-reset-challenge-options.interface.js → enroll-auth-factor.interface.js} +0 -0
- /package/lib/users/interfaces/{enroll-user-in-mfa-factor.interface.js → list-auth-factors-options.interface.js} +0 -0
- /package/lib/users/interfaces/{magic-auth-challenge.interface.js → reset-password-options.interface.js} +0 -0
- /package/lib/users/interfaces/{session.interface.js → send-password-reset-options.interface.js} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class GenericServerException extends Error {
|
|
2
2
|
readonly status: number;
|
|
3
|
+
readonly rawData: unknown;
|
|
3
4
|
readonly requestID: string;
|
|
4
5
|
readonly name: string;
|
|
5
|
-
readonly rawData: unknown;
|
|
6
6
|
readonly message: string;
|
|
7
7
|
constructor(status: number, message: string | undefined, rawData: unknown, requestID: string);
|
|
8
8
|
}
|
|
@@ -5,12 +5,12 @@ class GenericServerException extends Error {
|
|
|
5
5
|
constructor(status, message, rawData, requestID) {
|
|
6
6
|
super();
|
|
7
7
|
this.status = status;
|
|
8
|
+
this.rawData = rawData;
|
|
8
9
|
this.requestID = requestID;
|
|
9
10
|
this.name = 'GenericServerException';
|
|
10
11
|
this.message = 'The request could not be completed.';
|
|
11
12
|
if (message) {
|
|
12
13
|
this.message = message;
|
|
13
|
-
this.rawData = rawData;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -3,6 +3,7 @@ export declare class OauthException extends Error {
|
|
|
3
3
|
readonly requestID: string;
|
|
4
4
|
readonly error: string | undefined;
|
|
5
5
|
readonly errorDescription: string | undefined;
|
|
6
|
+
readonly rawData: unknown;
|
|
6
7
|
readonly name: string;
|
|
7
|
-
constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined);
|
|
8
|
+
constructor(status: number, requestID: string, error: string | undefined, errorDescription: string | undefined, rawData: unknown);
|
|
8
9
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OauthException = void 0;
|
|
4
4
|
class OauthException extends Error {
|
|
5
|
-
constructor(status, requestID, error, errorDescription) {
|
|
5
|
+
constructor(status, requestID, error, errorDescription, rawData) {
|
|
6
6
|
super();
|
|
7
7
|
this.status = status;
|
|
8
8
|
this.requestID = requestID;
|
|
9
9
|
this.error = error;
|
|
10
10
|
this.errorDescription = errorDescription;
|
|
11
|
+
this.rawData = rawData;
|
|
11
12
|
this.name = 'OauthException';
|
|
12
13
|
if (error && errorDescription) {
|
|
13
14
|
this.message = `Error: ${error}\nError Description: ${errorDescription}`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"object": "list",
|
|
3
|
+
"data": [
|
|
4
|
+
{
|
|
5
|
+
"object": "authentication_factor",
|
|
6
|
+
"id": "auth_factor_1234",
|
|
7
|
+
"created_at": "2022-03-15T20:39:19.892Z",
|
|
8
|
+
"updated_at": "2022-03-15T20:39:19.892Z",
|
|
9
|
+
"type": "totp",
|
|
10
|
+
"totp": {
|
|
11
|
+
"issuer": "WorkOS",
|
|
12
|
+
"qr_code": "qr-code-test",
|
|
13
|
+
"secret": "secret-test",
|
|
14
|
+
"uri": "uri-test",
|
|
15
|
+
"user": "some_user"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"list_metadata": {
|
|
20
|
+
"before": null,
|
|
21
|
+
"after": null
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AuthenticateWithCodeOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
code: string;
|
|
4
|
-
|
|
4
|
+
ipAddress?: string;
|
|
5
|
+
userAgent?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface AuthenticateUserWithCodeCredentials {
|
|
7
8
|
clientSecret: string | undefined;
|
|
8
9
|
}
|
|
9
|
-
export interface
|
|
10
|
+
export interface SerializedAuthenticateWithCodeOptions {
|
|
10
11
|
grant_type: 'authorization_code';
|
|
11
12
|
client_id: string;
|
|
12
13
|
client_secret: string | undefined;
|
|
13
14
|
code: string;
|
|
14
|
-
|
|
15
|
+
ip_address?: string;
|
|
16
|
+
user_agent?: string;
|
|
15
17
|
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AuthenticateWithMagicAuthOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
code: string;
|
|
4
|
-
|
|
4
|
+
userId: string;
|
|
5
5
|
ipAddress?: string;
|
|
6
6
|
userAgent?: string;
|
|
7
|
-
expiresIn?: number;
|
|
8
7
|
}
|
|
9
8
|
export interface AuthenticateUserWithMagicAuthCredentials {
|
|
10
9
|
clientSecret: string | undefined;
|
|
11
10
|
}
|
|
12
|
-
export interface
|
|
11
|
+
export interface SerializedAuthenticateWithMagicAuthOptions {
|
|
13
12
|
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code';
|
|
14
13
|
client_id: string;
|
|
15
14
|
client_secret: string | undefined;
|
|
16
15
|
code: string;
|
|
17
|
-
|
|
16
|
+
user_id: string;
|
|
18
17
|
ip_address?: string;
|
|
19
18
|
user_agent?: string;
|
|
20
|
-
expires_in?: number;
|
|
21
19
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface AuthenticateWithPasswordOptions {
|
|
2
2
|
clientId: string;
|
|
3
3
|
email: string;
|
|
4
4
|
password: string;
|
|
5
5
|
ipAddress?: string;
|
|
6
6
|
userAgent?: string;
|
|
7
|
-
expiresIn?: number;
|
|
8
7
|
}
|
|
9
8
|
export interface AuthenticateUserWithPasswordCredentials {
|
|
10
9
|
clientSecret: string | undefined;
|
|
11
10
|
}
|
|
12
|
-
export interface
|
|
11
|
+
export interface SerializedAuthenticateWithPasswordOptions {
|
|
13
12
|
grant_type: 'password';
|
|
14
13
|
client_id: string;
|
|
15
14
|
client_secret: string | undefined;
|
|
@@ -17,5 +16,4 @@ export interface SerializedAuthenticateUserWithPasswordOptions {
|
|
|
17
16
|
password: string;
|
|
18
17
|
ip_address?: string;
|
|
19
18
|
user_agent?: string;
|
|
20
|
-
expires_in?: number;
|
|
21
19
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface AuthenticateWithTotpOptions {
|
|
2
|
+
clientId: string;
|
|
3
|
+
code: string;
|
|
4
|
+
pendingAuthenticationToken: string;
|
|
5
|
+
authenticationChallengeId: string;
|
|
6
|
+
ipAddress?: string;
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthenticateUserWithTotpCredentials {
|
|
10
|
+
clientSecret: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface SerializedAuthenticateWithTotpOptions {
|
|
13
|
+
grant_type: 'urn:workos:oauth:grant-type:mfa-totp';
|
|
14
|
+
client_id: string;
|
|
15
|
+
client_secret: string | undefined;
|
|
16
|
+
code: string;
|
|
17
|
+
pending_authentication_token: string;
|
|
18
|
+
authentication_challenge_id: string;
|
|
19
|
+
ip_address?: string;
|
|
20
|
+
user_agent?: string;
|
|
21
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { User, UserResponse } from './user.interface';
|
|
2
|
-
import { Session, SessionResponse } from './session.interface';
|
|
3
2
|
export interface AuthenticationResponse {
|
|
4
|
-
session: Session;
|
|
5
3
|
user: User;
|
|
6
4
|
}
|
|
7
5
|
export interface AuthenticationResponseResponse {
|
|
8
|
-
session: SessionResponse;
|
|
9
6
|
user: UserResponse;
|
|
10
7
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export * from './add-user-to-organization-options.interface';
|
|
2
|
-
export * from './authenticate-
|
|
3
|
-
export * from './authenticate-
|
|
4
|
-
export * from './authenticate-
|
|
2
|
+
export * from './authenticate-with-magic-auth-options.interface';
|
|
3
|
+
export * from './authenticate-with-password-options.interface';
|
|
4
|
+
export * from './authenticate-with-code-options.interface';
|
|
5
|
+
export * from './authenticate-with-totp-options.interface';
|
|
5
6
|
export * from './authentication-response.interface';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './reset-password-options.interface';
|
|
8
|
+
export * from './send-password-reset-options.interface';
|
|
8
9
|
export * from './create-user-options.interface';
|
|
9
10
|
export * from './delete-user-options.interface';
|
|
10
|
-
export * from './enroll-
|
|
11
|
+
export * from './enroll-auth-factor.interface';
|
|
11
12
|
export * from './list-users-options.interface';
|
|
12
|
-
export * from './
|
|
13
|
+
export * from './list-auth-factors-options.interface';
|
|
13
14
|
export * from './remove-user-from-organization-options.interface';
|
|
14
15
|
export * from './send-magic-auth-code-options.interface';
|
|
15
16
|
export * from './send-verification-email-options';
|
|
16
|
-
export * from './session.interface';
|
|
17
17
|
export * from './update-user-options.interface';
|
|
18
18
|
export * from './update-user-password-options.interface';
|
|
19
19
|
export * from './user.interface';
|
|
@@ -15,21 +15,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./add-user-to-organization-options.interface"), exports);
|
|
18
|
-
__exportStar(require("./authenticate-
|
|
19
|
-
__exportStar(require("./authenticate-
|
|
20
|
-
__exportStar(require("./authenticate-
|
|
18
|
+
__exportStar(require("./authenticate-with-magic-auth-options.interface"), exports);
|
|
19
|
+
__exportStar(require("./authenticate-with-password-options.interface"), exports);
|
|
20
|
+
__exportStar(require("./authenticate-with-code-options.interface"), exports);
|
|
21
|
+
__exportStar(require("./authenticate-with-totp-options.interface"), exports);
|
|
21
22
|
__exportStar(require("./authentication-response.interface"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
23
|
-
__exportStar(require("./
|
|
23
|
+
__exportStar(require("./reset-password-options.interface"), exports);
|
|
24
|
+
__exportStar(require("./send-password-reset-options.interface"), exports);
|
|
24
25
|
__exportStar(require("./create-user-options.interface"), exports);
|
|
25
26
|
__exportStar(require("./delete-user-options.interface"), exports);
|
|
26
|
-
__exportStar(require("./enroll-
|
|
27
|
+
__exportStar(require("./enroll-auth-factor.interface"), exports);
|
|
27
28
|
__exportStar(require("./list-users-options.interface"), exports);
|
|
28
|
-
__exportStar(require("./
|
|
29
|
+
__exportStar(require("./list-auth-factors-options.interface"), exports);
|
|
29
30
|
__exportStar(require("./remove-user-from-organization-options.interface"), exports);
|
|
30
31
|
__exportStar(require("./send-magic-auth-code-options.interface"), exports);
|
|
31
32
|
__exportStar(require("./send-verification-email-options"), exports);
|
|
32
|
-
__exportStar(require("./session.interface"), exports);
|
|
33
33
|
__exportStar(require("./update-user-options.interface"), exports);
|
|
34
34
|
__exportStar(require("./update-user-password-options.interface"), exports);
|
|
35
35
|
__exportStar(require("./user.interface"), exports);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { User, UserResponse } from './user.interface';
|
|
2
|
-
export interface
|
|
2
|
+
export interface SendPasswordResetEmailOptions {
|
|
3
3
|
email: string;
|
|
4
4
|
passwordResetUrl: string;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface SerializedSendPasswordResetEmailOptions {
|
|
7
7
|
email: string;
|
|
8
8
|
password_reset_url: string;
|
|
9
9
|
}
|
|
10
|
-
export interface
|
|
10
|
+
export interface SendPasswordResetEmailResponse {
|
|
11
11
|
token: string;
|
|
12
12
|
user: User;
|
|
13
13
|
}
|
|
14
|
-
export interface
|
|
14
|
+
export interface SendPasswordResetEmailResponseResponse {
|
|
15
15
|
token: string;
|
|
16
16
|
user: UserResponse;
|
|
17
17
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithCodeCredentials, AuthenticateWithCodeOptions, SerializedAuthenticateWithCodeOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithCodeOptions: (options: AuthenticateWithCodeOptions & AuthenticateUserWithCodeCredentials) => SerializedAuthenticateWithCodeOptions;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthenticateWithCodeOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithCodeOptions = (options) => ({
|
|
5
|
+
grant_type: 'authorization_code',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
client_secret: options.clientSecret,
|
|
8
|
+
code: options.code,
|
|
9
|
+
ip_address: options.ipAddress,
|
|
10
|
+
user_agent: options.userAgent,
|
|
11
|
+
});
|
|
12
|
+
exports.serializeAuthenticateWithCodeOptions = serializeAuthenticateWithCodeOptions;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithMagicAuthCredentials, AuthenticateWithMagicAuthOptions, SerializedAuthenticateWithMagicAuthOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithMagicAuthOptions: (options: AuthenticateWithMagicAuthOptions & AuthenticateUserWithMagicAuthCredentials) => SerializedAuthenticateWithMagicAuthOptions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthenticateWithMagicAuthOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithMagicAuthOptions = (options) => ({
|
|
5
|
+
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
client_secret: options.clientSecret,
|
|
8
|
+
code: options.code,
|
|
9
|
+
user_id: options.userId,
|
|
10
|
+
ip_address: options.ipAddress,
|
|
11
|
+
user_agent: options.userAgent,
|
|
12
|
+
});
|
|
13
|
+
exports.serializeAuthenticateWithMagicAuthOptions = serializeAuthenticateWithMagicAuthOptions;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithPasswordCredentials, AuthenticateWithPasswordOptions, SerializedAuthenticateWithPasswordOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithPasswordOptions: (options: AuthenticateWithPasswordOptions & AuthenticateUserWithPasswordCredentials) => SerializedAuthenticateWithPasswordOptions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.serializeAuthenticateWithPasswordOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithPasswordOptions = (options) => ({
|
|
5
5
|
grant_type: 'password',
|
|
6
6
|
client_id: options.clientId,
|
|
7
7
|
client_secret: options.clientSecret,
|
|
@@ -9,6 +9,5 @@ const serializeAuthenticateUserWithPasswordOptions = (options) => ({
|
|
|
9
9
|
password: options.password,
|
|
10
10
|
ip_address: options.ipAddress,
|
|
11
11
|
user_agent: options.userAgent,
|
|
12
|
-
expires_in: options.expiresIn,
|
|
13
12
|
});
|
|
14
|
-
exports.
|
|
13
|
+
exports.serializeAuthenticateWithPasswordOptions = serializeAuthenticateWithPasswordOptions;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateUserWithTotpCredentials, AuthenticateWithTotpOptions, SerializedAuthenticateWithTotpOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithTotpOptions: (options: AuthenticateWithTotpOptions & AuthenticateUserWithTotpCredentials) => SerializedAuthenticateWithTotpOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthenticateWithTotpOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithTotpOptions = (options) => ({
|
|
5
|
+
grant_type: 'urn:workos:oauth:grant-type:mfa-totp',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
client_secret: options.clientSecret,
|
|
8
|
+
code: options.code,
|
|
9
|
+
authentication_challenge_id: options.authenticationChallengeId,
|
|
10
|
+
pending_authentication_token: options.pendingAuthenticationToken,
|
|
11
|
+
ip_address: options.ipAddress,
|
|
12
|
+
user_agent: options.userAgent,
|
|
13
|
+
});
|
|
14
|
+
exports.serializeAuthenticateWithTotpOptions = serializeAuthenticateWithTotpOptions;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deserializeAuthenticationResponse = void 0;
|
|
4
|
-
const session_serializer_1 = require("./session.serializer");
|
|
5
4
|
const user_serializer_1 = require("./user.serializer");
|
|
6
5
|
const deserializeAuthenticationResponse = (authenticationResponse) => ({
|
|
7
|
-
session: (0, session_serializer_1.deserializeSession)(authenticationResponse.session),
|
|
8
6
|
user: (0, user_serializer_1.deserializeUser)(authenticationResponse.user),
|
|
9
7
|
});
|
|
10
8
|
exports.deserializeAuthenticationResponse = deserializeAuthenticationResponse;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeEnrollAuthFactorOptions = void 0;
|
|
4
|
+
const serializeEnrollAuthFactorOptions = (options) => ({
|
|
5
|
+
type: options.type,
|
|
6
|
+
totp_issuer: options.totpIssuer,
|
|
7
|
+
totp_user: options.totpUser,
|
|
8
|
+
});
|
|
9
|
+
exports.serializeEnrollAuthFactorOptions = serializeEnrollAuthFactorOptions;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export * from './authenticate-
|
|
2
|
-
export * from './authenticate-
|
|
3
|
-
export * from './authenticate-
|
|
1
|
+
export * from './authenticate-with-code-options.serializer';
|
|
2
|
+
export * from './authenticate-with-magic-auth-options.serializer';
|
|
3
|
+
export * from './authenticate-with-password-options.serializer';
|
|
4
|
+
export * from './authenticate-with-totp-options.serializer';
|
|
4
5
|
export * from './authentication-response.serializer';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './enroll-auth-factor-options.serializer';
|
|
7
|
+
export * from './reset-password-options.serializer';
|
|
8
|
+
export * from './send-password-reset-email.serializer';
|
|
7
9
|
export * from './create-user-options.serializer';
|
|
8
10
|
export * from './send-magic-auth-code-options.serializer';
|
|
9
|
-
export * from './session.serializer';
|
|
10
11
|
export * from './update-user-options.serializer';
|
|
11
12
|
export * from './update-user-password-options.serializer';
|
|
12
13
|
export * from './user.serializer';
|
|
@@ -14,15 +14,16 @@ 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-
|
|
18
|
-
__exportStar(require("./authenticate-
|
|
19
|
-
__exportStar(require("./authenticate-
|
|
17
|
+
__exportStar(require("./authenticate-with-code-options.serializer"), exports);
|
|
18
|
+
__exportStar(require("./authenticate-with-magic-auth-options.serializer"), exports);
|
|
19
|
+
__exportStar(require("./authenticate-with-password-options.serializer"), exports);
|
|
20
|
+
__exportStar(require("./authenticate-with-totp-options.serializer"), exports);
|
|
20
21
|
__exportStar(require("./authentication-response.serializer"), exports);
|
|
21
|
-
__exportStar(require("./
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./enroll-auth-factor-options.serializer"), exports);
|
|
23
|
+
__exportStar(require("./reset-password-options.serializer"), exports);
|
|
24
|
+
__exportStar(require("./send-password-reset-email.serializer"), exports);
|
|
23
25
|
__exportStar(require("./create-user-options.serializer"), exports);
|
|
24
26
|
__exportStar(require("./send-magic-auth-code-options.serializer"), exports);
|
|
25
|
-
__exportStar(require("./session.serializer"), exports);
|
|
26
27
|
__exportStar(require("./update-user-options.serializer"), exports);
|
|
27
28
|
__exportStar(require("./update-user-password-options.serializer"), exports);
|
|
28
29
|
__exportStar(require("./user.serializer"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeResetPasswordOptions = void 0;
|
|
4
|
+
const serializeResetPasswordOptions = (options) => ({
|
|
5
|
+
token: options.token,
|
|
6
|
+
new_password: options.newPassword,
|
|
7
|
+
});
|
|
8
|
+
exports.serializeResetPasswordOptions = serializeResetPasswordOptions;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeSendMagicAuthCodeOptions = void 0;
|
|
4
4
|
const serializeSendMagicAuthCodeOptions = (options) => ({
|
|
5
|
-
|
|
5
|
+
email: options.email,
|
|
6
6
|
});
|
|
7
7
|
exports.serializeSendMagicAuthCodeOptions = serializeSendMagicAuthCodeOptions;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SendPasswordResetEmailOptions, SendPasswordResetEmailResponse, SendPasswordResetEmailResponseResponse, SerializedSendPasswordResetEmailOptions } from '../interfaces';
|
|
2
|
+
export declare const deserializeSendPasswordResetEmailResponse: (sendPasswordResetEmailResponse: SendPasswordResetEmailResponseResponse) => SendPasswordResetEmailResponse;
|
|
3
|
+
export declare const serializeSendPasswordResetEmailOptions: (options: SendPasswordResetEmailOptions) => SerializedSendPasswordResetEmailOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeSendPasswordResetEmailOptions = exports.deserializeSendPasswordResetEmailResponse = void 0;
|
|
4
|
+
const user_serializer_1 = require("./user.serializer");
|
|
5
|
+
const deserializeSendPasswordResetEmailResponse = (sendPasswordResetEmailResponse) => ({
|
|
6
|
+
token: sendPasswordResetEmailResponse.token,
|
|
7
|
+
user: (0, user_serializer_1.deserializeUser)(sendPasswordResetEmailResponse.user),
|
|
8
|
+
});
|
|
9
|
+
exports.deserializeSendPasswordResetEmailResponse = deserializeSendPasswordResetEmailResponse;
|
|
10
|
+
const serializeSendPasswordResetEmailOptions = (options) => ({
|
|
11
|
+
email: options.email,
|
|
12
|
+
password_reset_url: options.passwordResetUrl,
|
|
13
|
+
});
|
|
14
|
+
exports.serializeSendPasswordResetEmailOptions = serializeSendPasswordResetEmailOptions;
|
package/lib/users/users.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkOS } from '../workos';
|
|
2
2
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
3
|
-
import { AddUserToOrganizationOptions,
|
|
3
|
+
import { AddUserToOrganizationOptions, AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithTotpOptions, AuthenticationResponse, ResetPasswordOptions, SendPasswordResetEmailOptions, SendPasswordResetEmailResponse, CreateUserOptions, DeleteUserOptions, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, RemoveUserFromOrganizationOptions, SendMagicAuthCodeOptions, SendVerificationEmailOptions, UpdateUserOptions, UpdateUserPasswordOptions, User, VerifyEmailCodeOptions } from './interfaces';
|
|
4
4
|
import { Challenge, Factor } from '../mfa/interfaces';
|
|
5
5
|
export declare class Users {
|
|
6
6
|
private readonly workos;
|
|
@@ -8,25 +8,31 @@ export declare class Users {
|
|
|
8
8
|
getUser(userId: string): Promise<User>;
|
|
9
9
|
listUsers(options?: ListUsersOptions): Promise<AutoPaginatable<User>>;
|
|
10
10
|
createUser(payload: CreateUserOptions): Promise<User>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
12
|
+
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
13
|
+
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
14
|
+
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
14
15
|
sendVerificationEmail({ userId, }: SendVerificationEmailOptions): Promise<{
|
|
15
16
|
user: User;
|
|
16
17
|
}>;
|
|
17
18
|
sendMagicAuthCode(options: SendMagicAuthCodeOptions): Promise<{
|
|
18
19
|
user: User;
|
|
19
20
|
}>;
|
|
20
|
-
verifyEmailCode({ code, userId, }: VerifyEmailCodeOptions): Promise<
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
verifyEmailCode({ code, userId, }: VerifyEmailCodeOptions): Promise<{
|
|
22
|
+
user: User;
|
|
23
|
+
}>;
|
|
24
|
+
sendPasswordResetEmail(payload: SendPasswordResetEmailOptions): Promise<SendPasswordResetEmailResponse>;
|
|
25
|
+
resetPassword(payload: ResetPasswordOptions): Promise<{
|
|
26
|
+
user: User;
|
|
27
|
+
}>;
|
|
23
28
|
addUserToOrganization({ userId, organizationId, }: AddUserToOrganizationOptions): Promise<User>;
|
|
24
29
|
removeUserFromOrganization({ userId, organizationId, }: RemoveUserFromOrganizationOptions): Promise<User>;
|
|
25
30
|
updateUser(payload: UpdateUserOptions): Promise<User>;
|
|
26
31
|
updateUserPassword(payload: UpdateUserPasswordOptions): Promise<User>;
|
|
27
|
-
|
|
32
|
+
enrollAuthFactor(payload: EnrollAuthFactorOptions): Promise<{
|
|
28
33
|
authenticationFactor: Factor;
|
|
29
34
|
authenticationChallenge: Challenge;
|
|
30
35
|
}>;
|
|
36
|
+
listAuthFactors(options: ListAuthFactorsOptions): Promise<AutoPaginatable<Factor>>;
|
|
31
37
|
deleteUser(payload: DeleteUserOptions): Promise<void>;
|
|
32
38
|
}
|
package/lib/users/users.js
CHANGED
|
@@ -14,7 +14,6 @@ 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
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");
|
|
18
17
|
class Users {
|
|
19
18
|
constructor(workos) {
|
|
20
19
|
this.workos = workos;
|
|
@@ -36,21 +35,27 @@ class Users {
|
|
|
36
35
|
return (0, serializers_1.deserializeUser)(data);
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
authenticateWithMagicAuth(payload) {
|
|
40
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const { data } = yield this.workos.post('/users/
|
|
40
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateWithMagicAuthOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
42
41
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
43
42
|
});
|
|
44
43
|
}
|
|
45
|
-
|
|
44
|
+
authenticateWithPassword(payload) {
|
|
46
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
const { data } = yield this.workos.post('/users/
|
|
46
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateWithPasswordOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
48
47
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
authenticateWithCode(payload) {
|
|
52
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const { data } = yield this.workos.post('/users/
|
|
52
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateWithCodeOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
53
|
+
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
authenticateWithTotp(payload) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const { data } = yield this.workos.post('/users/authenticate', (0, serializers_1.serializeAuthenticateWithTotpOptions)(Object.assign(Object.assign({}, payload), { clientSecret: this.workos.key })));
|
|
54
59
|
return (0, serializers_1.deserializeAuthenticationResponse)(data);
|
|
55
60
|
});
|
|
56
61
|
}
|
|
@@ -71,19 +76,19 @@ class Users {
|
|
|
71
76
|
const { data } = yield this.workos.post(`/users/${userId}/verify_email_code`, {
|
|
72
77
|
code,
|
|
73
78
|
});
|
|
74
|
-
return (0, serializers_1.deserializeUser)(data);
|
|
79
|
+
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
75
80
|
});
|
|
76
81
|
}
|
|
77
|
-
|
|
82
|
+
sendPasswordResetEmail(payload) {
|
|
78
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const { data } = yield this.workos.post('/users/
|
|
80
|
-
return (0, serializers_1.
|
|
84
|
+
const { data } = yield this.workos.post('/users/send_password_reset_email', (0, serializers_1.serializeSendPasswordResetEmailOptions)(payload));
|
|
85
|
+
return (0, serializers_1.deserializeSendPasswordResetEmailResponse)(data);
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
|
-
|
|
88
|
+
resetPassword(payload) {
|
|
84
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const { data } = yield this.workos.post('/users/password_reset', (0, serializers_1.
|
|
86
|
-
return (0, serializers_1.deserializeUser)(data);
|
|
90
|
+
const { data } = yield this.workos.post('/users/password_reset', (0, serializers_1.serializeResetPasswordOptions)(payload));
|
|
91
|
+
return { user: (0, serializers_1.deserializeUser)(data.user) };
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
addUserToOrganization({ userId, organizationId, }) {
|
|
@@ -112,15 +117,20 @@ class Users {
|
|
|
112
117
|
return (0, serializers_1.deserializeUser)(data);
|
|
113
118
|
});
|
|
114
119
|
}
|
|
115
|
-
|
|
120
|
+
enrollAuthFactor(payload) {
|
|
116
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
const { data } = yield this.workos.post(`/users/${payload.userId}/auth/factors`, (0,
|
|
122
|
+
const { data } = yield this.workos.post(`/users/${payload.userId}/auth/factors`, (0, serializers_1.serializeEnrollAuthFactorOptions)(payload));
|
|
118
123
|
return {
|
|
119
124
|
authenticationFactor: (0, serializers_2.deserializeFactor)(data.authentication_factor),
|
|
120
125
|
authenticationChallenge: (0, serializers_2.deserializeChallenge)(data.authentication_challenge),
|
|
121
126
|
};
|
|
122
127
|
});
|
|
123
128
|
}
|
|
129
|
+
listAuthFactors(options) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/users/${options.userId}/auth/factors`, serializers_2.deserializeFactor, options), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, `/users/${options.userId}/auth/factors`, serializers_2.deserializeFactor, params), options);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
124
134
|
deleteUser(payload) {
|
|
125
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
136
|
yield this.workos.delete(`/users/${payload.userId}`);
|
package/lib/users/users.spec.js
CHANGED
|
@@ -17,7 +17,7 @@ const axios_mock_adapter_1 = __importDefault(require("axios-mock-adapter"));
|
|
|
17
17
|
const workos_1 = require("../workos");
|
|
18
18
|
const user_json_1 = __importDefault(require("./fixtures/user.json"));
|
|
19
19
|
const list_users_json_1 = __importDefault(require("./fixtures/list-users.json"));
|
|
20
|
-
const
|
|
20
|
+
const list_factors_json_1 = __importDefault(require("./fixtures/list-factors.json"));
|
|
21
21
|
const mock = new axios_mock_adapter_1.default(axios_1.default);
|
|
22
22
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
23
23
|
const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
|
|
@@ -98,61 +98,48 @@ describe('UserManagement', () => {
|
|
|
98
98
|
});
|
|
99
99
|
describe('authenticateUserWithMagicAuth', () => {
|
|
100
100
|
it('sends a magic auth authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
mock.onPost('/users/
|
|
101
|
+
mock.onPost('/users/authenticate').reply(200, {
|
|
102
102
|
user: user_json_1.default,
|
|
103
|
-
session: session_json_1.default,
|
|
104
103
|
});
|
|
105
|
-
const resp = yield workos.users.
|
|
104
|
+
const resp = yield workos.users.authenticateWithMagicAuth({
|
|
106
105
|
clientId: 'proj_whatever',
|
|
107
106
|
code: '123456',
|
|
108
|
-
|
|
107
|
+
userId: user_json_1.default.id,
|
|
109
108
|
});
|
|
110
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
109
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
111
110
|
expect(resp).toMatchObject({
|
|
112
111
|
user: {
|
|
113
112
|
email: 'test01@example.com',
|
|
114
113
|
},
|
|
115
|
-
session: {
|
|
116
|
-
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
117
|
-
token: 'really-long-token',
|
|
118
|
-
},
|
|
119
114
|
});
|
|
120
115
|
}));
|
|
121
116
|
});
|
|
122
117
|
describe('authenticateUserWithPassword', () => {
|
|
123
118
|
it('sends an password authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
-
mock.onPost('/users/
|
|
119
|
+
mock.onPost('/users/authenticate').reply(200, {
|
|
125
120
|
user: user_json_1.default,
|
|
126
|
-
session: session_json_1.default,
|
|
127
121
|
});
|
|
128
|
-
const resp = yield workos.users.
|
|
122
|
+
const resp = yield workos.users.authenticateWithPassword({
|
|
129
123
|
clientId: 'proj_whatever',
|
|
130
124
|
email: 'test01@example.com',
|
|
131
125
|
password: 'extra-secure',
|
|
132
126
|
});
|
|
133
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
127
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
134
128
|
expect(resp).toMatchObject({
|
|
135
129
|
user: {
|
|
136
130
|
email: 'test01@example.com',
|
|
137
131
|
},
|
|
138
|
-
session: {
|
|
139
|
-
id: 'session_01H5K05VP5CPCXJA5Z7G191GS4',
|
|
140
|
-
token: 'really-long-token',
|
|
141
|
-
},
|
|
142
132
|
});
|
|
143
133
|
}));
|
|
144
134
|
});
|
|
145
135
|
describe('authenticateUserWithCode', () => {
|
|
146
136
|
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
-
mock
|
|
148
|
-
|
|
149
|
-
.reply(200, { user: user_json_1.default, session: session_json_1.default });
|
|
150
|
-
const resp = yield workos.users.authenticateUserWithCode({
|
|
137
|
+
mock.onPost('/users/authenticate').reply(200, { user: user_json_1.default });
|
|
138
|
+
const resp = yield workos.users.authenticateWithCode({
|
|
151
139
|
clientId: 'proj_whatever',
|
|
152
140
|
code: 'or this',
|
|
153
|
-
expiresIn: 15,
|
|
154
141
|
});
|
|
155
|
-
expect(mock.history.post[0].url).toEqual('/users/
|
|
142
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
156
143
|
expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
|
|
157
144
|
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
158
145
|
grant_type: 'authorization_code',
|
|
@@ -161,9 +148,30 @@ describe('UserManagement', () => {
|
|
|
161
148
|
user: {
|
|
162
149
|
email: 'test01@example.com',
|
|
163
150
|
},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
});
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
describe('authenticateUserWithTotp', () => {
|
|
155
|
+
it('sends a token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
mock.onPost('/users/authenticate').reply(200, { user: user_json_1.default });
|
|
157
|
+
const resp = yield workos.users.authenticateWithTotp({
|
|
158
|
+
clientId: 'proj_whatever',
|
|
159
|
+
code: 'or this',
|
|
160
|
+
authenticationChallengeId: 'auth_challenge_01H96FETXGTW1QMBSBT2T36PW0',
|
|
161
|
+
pendingAuthenticationToken: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
|
|
162
|
+
});
|
|
163
|
+
expect(mock.history.post[0].url).toEqual('/users/authenticate');
|
|
164
|
+
expect(JSON.parse(mock.history.post[0].data)).toMatchObject({
|
|
165
|
+
client_id: 'proj_whatever',
|
|
166
|
+
code: 'or this',
|
|
167
|
+
client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
|
|
168
|
+
grant_type: 'urn:workos:oauth:grant-type:mfa-totp',
|
|
169
|
+
authentication_challenge_id: 'auth_challenge_01H96FETXGTW1QMBSBT2T36PW0',
|
|
170
|
+
pending_authentication_token: 'cTDQJTTkTkkVYxQUlKBIxEsFs',
|
|
171
|
+
});
|
|
172
|
+
expect(resp).toMatchObject({
|
|
173
|
+
user: {
|
|
174
|
+
email: 'test01@example.com',
|
|
167
175
|
},
|
|
168
176
|
});
|
|
169
177
|
}));
|
|
@@ -194,13 +202,13 @@ describe('UserManagement', () => {
|
|
|
194
202
|
it('sends a Complete Email Verification request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
203
|
mock
|
|
196
204
|
.onPost(`/users/user_123/verify_email_code`)
|
|
197
|
-
.reply(200, user_json_1.default);
|
|
205
|
+
.reply(200, { user: user_json_1.default });
|
|
198
206
|
const resp = yield workos.users.verifyEmailCode({
|
|
199
207
|
userId: 'user_123',
|
|
200
208
|
code: '123456',
|
|
201
209
|
});
|
|
202
210
|
expect(mock.history.post[0].url).toEqual(`/users/user_123/verify_email_code`);
|
|
203
|
-
expect(resp).toMatchObject({
|
|
211
|
+
expect(resp.user).toMatchObject({
|
|
204
212
|
email: 'test01@example.com',
|
|
205
213
|
});
|
|
206
214
|
}));
|
|
@@ -210,7 +218,7 @@ describe('UserManagement', () => {
|
|
|
210
218
|
it('sends a Send Magic Auth Code request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
211
219
|
mock
|
|
212
220
|
.onPost('/users/magic_auth/send', {
|
|
213
|
-
|
|
221
|
+
email: 'bob.loblaw@example.com',
|
|
214
222
|
})
|
|
215
223
|
.reply(200, {
|
|
216
224
|
user: {
|
|
@@ -224,7 +232,7 @@ describe('UserManagement', () => {
|
|
|
224
232
|
},
|
|
225
233
|
});
|
|
226
234
|
const response = yield workos.users.sendMagicAuthCode({
|
|
227
|
-
|
|
235
|
+
email: 'bob.loblaw@example.com',
|
|
228
236
|
});
|
|
229
237
|
expect(mock.history.post[0].url).toEqual('/users/magic_auth/send');
|
|
230
238
|
expect(response).toMatchObject({
|
|
@@ -242,15 +250,15 @@ describe('UserManagement', () => {
|
|
|
242
250
|
});
|
|
243
251
|
describe('createPasswordResetChallenge', () => {
|
|
244
252
|
it('sends a Create Password Reset Challenge request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
245
|
-
mock.onPost(`/users/
|
|
253
|
+
mock.onPost(`/users/send_password_reset_email`).reply(200, {
|
|
246
254
|
token: 'password-reset-token',
|
|
247
255
|
user: user_json_1.default,
|
|
248
256
|
});
|
|
249
|
-
const resp = yield workos.users.
|
|
257
|
+
const resp = yield workos.users.sendPasswordResetEmail({
|
|
250
258
|
email: 'test01@example.com',
|
|
251
259
|
passwordResetUrl: 'https://example.com/forgot-password',
|
|
252
260
|
});
|
|
253
|
-
expect(mock.history.post[0].url).toEqual(`/users/
|
|
261
|
+
expect(mock.history.post[0].url).toEqual(`/users/send_password_reset_email`);
|
|
254
262
|
expect(resp).toMatchObject({
|
|
255
263
|
token: 'password-reset-token',
|
|
256
264
|
user: {
|
|
@@ -261,13 +269,13 @@ describe('UserManagement', () => {
|
|
|
261
269
|
});
|
|
262
270
|
describe('completePasswordReset', () => {
|
|
263
271
|
it('sends a completePasswordReset request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
264
|
-
mock.onPost(`/users/password_reset`).reply(200, user_json_1.default);
|
|
265
|
-
const resp = yield workos.users.
|
|
272
|
+
mock.onPost(`/users/password_reset`).reply(200, { user: user_json_1.default });
|
|
273
|
+
const resp = yield workos.users.resetPassword({
|
|
266
274
|
token: '',
|
|
267
275
|
newPassword: 'correct horse battery staple',
|
|
268
276
|
});
|
|
269
277
|
expect(mock.history.post[0].url).toEqual(`/users/password_reset`);
|
|
270
|
-
expect(resp).toMatchObject({
|
|
278
|
+
expect(resp.user).toMatchObject({
|
|
271
279
|
email: 'test01@example.com',
|
|
272
280
|
});
|
|
273
281
|
}));
|
|
@@ -350,8 +358,8 @@ describe('UserManagement', () => {
|
|
|
350
358
|
});
|
|
351
359
|
}));
|
|
352
360
|
});
|
|
353
|
-
describe('
|
|
354
|
-
it('sends an
|
|
361
|
+
describe('enrollAuthFactor', () => {
|
|
362
|
+
it('sends an enrollAuthFactor request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
355
363
|
mock.onPost(`/users/${userId}/auth/factors`).reply(200, {
|
|
356
364
|
authentication_factor: {
|
|
357
365
|
object: 'authentication_factor',
|
|
@@ -377,7 +385,7 @@ describe('UserManagement', () => {
|
|
|
377
385
|
authentication_factor_id: 'auth_factor_1234',
|
|
378
386
|
},
|
|
379
387
|
});
|
|
380
|
-
const resp = yield workos.users.
|
|
388
|
+
const resp = yield workos.users.enrollAuthFactor({
|
|
381
389
|
userId,
|
|
382
390
|
type: 'totp',
|
|
383
391
|
totpIssuer: 'WorkOS',
|
|
@@ -411,6 +419,36 @@ describe('UserManagement', () => {
|
|
|
411
419
|
});
|
|
412
420
|
}));
|
|
413
421
|
});
|
|
422
|
+
describe('listAuthFactors', () => {
|
|
423
|
+
it('sends a listAuthFactors request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
424
|
+
mock.onGet(`/users/${userId}/auth/factors`).reply(200, list_factors_json_1.default);
|
|
425
|
+
const resp = yield workos.users.listAuthFactors({ userId });
|
|
426
|
+
expect(mock.history.get[0].url).toEqual(`/users/${userId}/auth/factors`);
|
|
427
|
+
expect(resp).toMatchObject({
|
|
428
|
+
object: 'list',
|
|
429
|
+
data: [
|
|
430
|
+
{
|
|
431
|
+
object: 'authentication_factor',
|
|
432
|
+
id: 'auth_factor_1234',
|
|
433
|
+
createdAt: '2022-03-15T20:39:19.892Z',
|
|
434
|
+
updatedAt: '2022-03-15T20:39:19.892Z',
|
|
435
|
+
type: 'totp',
|
|
436
|
+
totp: {
|
|
437
|
+
issuer: 'WorkOS',
|
|
438
|
+
qrCode: 'qr-code-test',
|
|
439
|
+
secret: 'secret-test',
|
|
440
|
+
uri: 'uri-test',
|
|
441
|
+
user: 'some_user',
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
],
|
|
445
|
+
listMetadata: {
|
|
446
|
+
before: null,
|
|
447
|
+
after: null,
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
}));
|
|
451
|
+
});
|
|
414
452
|
describe('deleteUser', () => {
|
|
415
453
|
it('sends a deleteUser request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
416
454
|
mock.onDelete(`/users/${userId}`).reply(200);
|
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.7.0';
|
|
31
31
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
32
32
|
class WorkOS {
|
|
33
33
|
constructor(key, options = {}) {
|
|
@@ -170,7 +170,7 @@ class WorkOS {
|
|
|
170
170
|
}
|
|
171
171
|
default: {
|
|
172
172
|
if (error || errorDescription) {
|
|
173
|
-
throw new exceptions_1.OauthException(status, requestID, error, errorDescription);
|
|
173
|
+
throw new exceptions_1.OauthException(status, requestID, error, errorDescription, data);
|
|
174
174
|
}
|
|
175
175
|
else if (code && errors) {
|
|
176
176
|
// Note: ideally this should be mapped directly with a `400` status code.
|
package/lib/workos.spec.js
CHANGED
|
@@ -149,7 +149,7 @@ describe('WorkOS', () => {
|
|
|
149
149
|
'X-Request-ID': 'a-request-id',
|
|
150
150
|
});
|
|
151
151
|
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
152
|
-
yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description'));
|
|
152
|
+
yield expect(workos.post('/path', {})).rejects.toStrictEqual(new exceptions_1.OauthException(400, 'a-request-id', 'error', 'error description', { error: 'error', error_description: 'error description' }));
|
|
153
153
|
}));
|
|
154
154
|
});
|
|
155
155
|
});
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export interface Session {
|
|
2
|
-
id: string;
|
|
3
|
-
createdAt: string;
|
|
4
|
-
expiresAt: string;
|
|
5
|
-
authorizedOrganizations: AuthorizedOrganization[];
|
|
6
|
-
unauthorizedOrganizations: UnauthorizedOrganization[];
|
|
7
|
-
token: string;
|
|
8
|
-
}
|
|
9
|
-
interface OrganizationSummary {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
}
|
|
13
|
-
interface AuthorizedOrganization {
|
|
14
|
-
organization: OrganizationSummary;
|
|
15
|
-
}
|
|
16
|
-
type SessionAuthenticationMethod = 'GoogleOauth' | 'MagicAuth' | 'MicrosoftOauth' | 'Password';
|
|
17
|
-
export type UnauthorizedOrganizationReason = {
|
|
18
|
-
type: 'authentication_method_required';
|
|
19
|
-
allowedAuthenticationMethods: SessionAuthenticationMethod[];
|
|
20
|
-
};
|
|
21
|
-
export type UnauthorizedOrganizationReasonResponse = {
|
|
22
|
-
type: 'authentication_method_required';
|
|
23
|
-
allowed_authentication_methods: SessionAuthenticationMethod[];
|
|
24
|
-
};
|
|
25
|
-
export interface UnauthorizedOrganization {
|
|
26
|
-
organization: OrganizationSummary;
|
|
27
|
-
reasons: UnauthorizedOrganizationReason[];
|
|
28
|
-
}
|
|
29
|
-
export interface UnauthorizedOrganizationResponse {
|
|
30
|
-
organization: OrganizationSummary;
|
|
31
|
-
reasons: UnauthorizedOrganizationReasonResponse[];
|
|
32
|
-
}
|
|
33
|
-
export interface SessionResponse {
|
|
34
|
-
id: string;
|
|
35
|
-
created_at: string;
|
|
36
|
-
expires_at: string;
|
|
37
|
-
authorized_organizations: AuthorizedOrganization[];
|
|
38
|
-
unauthorized_organizations: UnauthorizedOrganizationResponse[];
|
|
39
|
-
token: string;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AuthenticateUserWithCodeCredentials, AuthenticateUserWithCodeOptions, SerializedAuthenticateUserWithCodeOptions } from '../interfaces';
|
|
2
|
-
export declare const serializeAuthenticateUserWithCodeOptions: (options: AuthenticateUserWithCodeOptions & AuthenticateUserWithCodeCredentials) => SerializedAuthenticateUserWithCodeOptions;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeAuthenticateUserWithCodeOptions = void 0;
|
|
4
|
-
const serializeAuthenticateUserWithCodeOptions = (options) => ({
|
|
5
|
-
grant_type: 'authorization_code',
|
|
6
|
-
client_id: options.clientId,
|
|
7
|
-
client_secret: options.clientSecret,
|
|
8
|
-
code: options.code,
|
|
9
|
-
expires_in: options.expiresIn,
|
|
10
|
-
});
|
|
11
|
-
exports.serializeAuthenticateUserWithCodeOptions = serializeAuthenticateUserWithCodeOptions;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AuthenticateUserWithMagicAuthCredentials, AuthenticateUserWithMagicAuthOptions, SerializedAuthenticateUserWithMagicAuthOptions } from '../interfaces';
|
|
2
|
-
export declare const serializeAuthenticateUserWithMagicAuthOptions: (options: AuthenticateUserWithMagicAuthOptions & AuthenticateUserWithMagicAuthCredentials) => SerializedAuthenticateUserWithMagicAuthOptions;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeAuthenticateUserWithMagicAuthOptions = void 0;
|
|
4
|
-
const serializeAuthenticateUserWithMagicAuthOptions = (options) => ({
|
|
5
|
-
grant_type: 'urn:workos:oauth:grant-type:magic-auth:code',
|
|
6
|
-
client_id: options.clientId,
|
|
7
|
-
client_secret: options.clientSecret,
|
|
8
|
-
code: options.code,
|
|
9
|
-
magic_auth_challenge_id: options.magicAuthChallengeId,
|
|
10
|
-
ip_address: options.ipAddress,
|
|
11
|
-
user_agent: options.userAgent,
|
|
12
|
-
expires_in: options.expiresIn,
|
|
13
|
-
});
|
|
14
|
-
exports.serializeAuthenticateUserWithMagicAuthOptions = serializeAuthenticateUserWithMagicAuthOptions;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { AuthenticateUserWithPasswordCredentials, AuthenticateUserWithPasswordOptions, SerializedAuthenticateUserWithPasswordOptions } from '../interfaces';
|
|
2
|
-
export declare const serializeAuthenticateUserWithPasswordOptions: (options: AuthenticateUserWithPasswordOptions & AuthenticateUserWithPasswordCredentials) => SerializedAuthenticateUserWithPasswordOptions;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeCompletePasswordResetOptions = void 0;
|
|
4
|
-
const serializeCompletePasswordResetOptions = (options) => ({
|
|
5
|
-
token: options.token,
|
|
6
|
-
new_password: options.newPassword,
|
|
7
|
-
});
|
|
8
|
-
exports.serializeCompletePasswordResetOptions = serializeCompletePasswordResetOptions;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { CreatePasswordResetChallengeOptions, CreatePasswordResetChallengeResponse, CreatePasswordResetChallengeResponseResponse, SerializedCreatePasswordResetChallengeOptions } from '../interfaces';
|
|
2
|
-
export declare const deserializeCreatePasswordResetChallengeResponse: (createPasswordResetChallengeResponse: CreatePasswordResetChallengeResponseResponse) => CreatePasswordResetChallengeResponse;
|
|
3
|
-
export declare const serializeCreatePasswordResetChallengeOptions: (options: CreatePasswordResetChallengeOptions) => SerializedCreatePasswordResetChallengeOptions;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeCreatePasswordResetChallengeOptions = exports.deserializeCreatePasswordResetChallengeResponse = void 0;
|
|
4
|
-
const user_serializer_1 = require("./user.serializer");
|
|
5
|
-
const deserializeCreatePasswordResetChallengeResponse = (createPasswordResetChallengeResponse) => ({
|
|
6
|
-
token: createPasswordResetChallengeResponse.token,
|
|
7
|
-
user: (0, user_serializer_1.deserializeUser)(createPasswordResetChallengeResponse.user),
|
|
8
|
-
});
|
|
9
|
-
exports.deserializeCreatePasswordResetChallengeResponse = deserializeCreatePasswordResetChallengeResponse;
|
|
10
|
-
const serializeCreatePasswordResetChallengeOptions = (options) => ({
|
|
11
|
-
email: options.email,
|
|
12
|
-
password_reset_url: options.passwordResetUrl,
|
|
13
|
-
});
|
|
14
|
-
exports.serializeCreatePasswordResetChallengeOptions = serializeCreatePasswordResetChallengeOptions;
|
|
@@ -1,9 +0,0 @@
|
|
|
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,4 +0,0 @@
|
|
|
1
|
-
import { Session, SessionResponse, UnauthorizedOrganization, UnauthorizedOrganizationReason, UnauthorizedOrganizationReasonResponse, UnauthorizedOrganizationResponse } from '../interfaces/session.interface';
|
|
2
|
-
export declare const deserializeSession: (session: SessionResponse) => Session;
|
|
3
|
-
export declare const deserializeUnauthorizedOrganization: (unauthorizedOrganization: UnauthorizedOrganizationResponse) => UnauthorizedOrganization;
|
|
4
|
-
export declare const deserializeUnauthorizedOrganizationReason: (unauthorizedOrganizationReason: UnauthorizedOrganizationReasonResponse) => UnauthorizedOrganizationReason;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deserializeUnauthorizedOrganizationReason = exports.deserializeUnauthorizedOrganization = exports.deserializeSession = void 0;
|
|
4
|
-
const deserializeSession = (session) => ({
|
|
5
|
-
id: session.id,
|
|
6
|
-
createdAt: session.created_at,
|
|
7
|
-
expiresAt: session.expires_at,
|
|
8
|
-
authorizedOrganizations: session.authorized_organizations,
|
|
9
|
-
unauthorizedOrganizations: session.unauthorized_organizations.map(exports.deserializeUnauthorizedOrganization),
|
|
10
|
-
token: session.token,
|
|
11
|
-
});
|
|
12
|
-
exports.deserializeSession = deserializeSession;
|
|
13
|
-
const deserializeUnauthorizedOrganization = (unauthorizedOrganization) => ({
|
|
14
|
-
organization: unauthorizedOrganization.organization,
|
|
15
|
-
reasons: unauthorizedOrganization.reasons.map(exports.deserializeUnauthorizedOrganizationReason),
|
|
16
|
-
});
|
|
17
|
-
exports.deserializeUnauthorizedOrganization = deserializeUnauthorizedOrganization;
|
|
18
|
-
const deserializeUnauthorizedOrganizationReason = (unauthorizedOrganizationReason) => ({
|
|
19
|
-
type: unauthorizedOrganizationReason.type,
|
|
20
|
-
allowedAuthenticationMethods: unauthorizedOrganizationReason.allowed_authentication_methods,
|
|
21
|
-
});
|
|
22
|
-
exports.deserializeUnauthorizedOrganizationReason = deserializeUnauthorizedOrganizationReason;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/lib/users/interfaces/{session.interface.js → send-password-reset-options.interface.js}
RENAMED
|
File without changes
|