@workos-inc/node 7.56.0 → 7.59.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/interfaces/event.interface.d.ts +26 -2
- package/lib/common/serializers/event.serializer.js +3 -0
- package/lib/organization-domains/interfaces/organization-domain.interface.d.ts +4 -0
- package/lib/organization-domains/serializers/organization-domain.serializer.js +2 -0
- package/lib/user-management/interfaces/authenticate-with-code-and-verifier-options.interface.d.ts +12 -0
- package/lib/user-management/interfaces/authenticate-with-code-and-verifier-options.interface.js +2 -0
- package/lib/user-management/interfaces/authenticate-with-options-base.interface.d.ts +5 -0
- package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +1 -0
- package/lib/user-management/interfaces/index.d.ts +1 -0
- package/lib/user-management/interfaces/index.js +1 -0
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.d.ts +2 -0
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.js +13 -0
- package/lib/user-management/serializers/index.d.ts +1 -0
- package/lib/user-management/serializers/index.js +1 -0
- package/lib/user-management/user-management.d.ts +3 -2
- package/lib/user-management/user-management.js +12 -1
- package/lib/user-management/user-management.spec.js +107 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -426,7 +426,31 @@ export interface OrganizationDomainVerificationFailedEventResponse extends Event
|
|
|
426
426
|
event: 'organization_domain.verification_failed';
|
|
427
427
|
data: OrganizationDomainResponse;
|
|
428
428
|
}
|
|
429
|
-
export
|
|
430
|
-
|
|
429
|
+
export interface OrganizationDomainCreatedEvent extends EventBase {
|
|
430
|
+
event: 'organization_domain.created';
|
|
431
|
+
data: OrganizationDomain;
|
|
432
|
+
}
|
|
433
|
+
export interface OrganizationDomainCreatedEventResponse extends EventResponseBase {
|
|
434
|
+
event: 'organization_domain.created';
|
|
435
|
+
data: OrganizationDomainResponse;
|
|
436
|
+
}
|
|
437
|
+
export interface OrganizationDomainUpdatedEvent extends EventBase {
|
|
438
|
+
event: 'organization_domain.updated';
|
|
439
|
+
data: OrganizationDomain;
|
|
440
|
+
}
|
|
441
|
+
export interface OrganizationDomainUpdatedEventResponse extends EventResponseBase {
|
|
442
|
+
event: 'organization_domain.updated';
|
|
443
|
+
data: OrganizationDomainResponse;
|
|
444
|
+
}
|
|
445
|
+
export interface OrganizationDomainDeletedEvent extends EventBase {
|
|
446
|
+
event: 'organization_domain.deleted';
|
|
447
|
+
data: OrganizationDomain;
|
|
448
|
+
}
|
|
449
|
+
export interface OrganizationDomainDeletedEventResponse extends EventResponseBase {
|
|
450
|
+
event: 'organization_domain.deleted';
|
|
451
|
+
data: OrganizationDomainResponse;
|
|
452
|
+
}
|
|
453
|
+
export type Event = AuthenticationEmailVerificationSucceededEvent | AuthenticationMfaSucceededEvent | AuthenticationOAuthFailedEvent | AuthenticationOAuthSucceededEvent | AuthenticationSSOFailedEvent | AuthenticationSSOSucceededEvent | AuthenticationPasswordFailedEvent | AuthenticationPasswordSucceededEvent | AuthenticationMagicAuthFailedEvent | AuthenticationMagicAuthSucceededEvent | AuthenticationRadarRiskDetectedEvent | ConnectionActivatedEvent | ConnectionDeactivatedEvent | ConnectionDeletedEvent | DsyncActivatedEvent | DsyncDeactivatedEvent | DsyncDeletedEvent | DsyncGroupCreatedEvent | DsyncGroupUpdatedEvent | DsyncGroupDeletedEvent | DsyncGroupUserAddedEvent | DsyncGroupUserRemovedEvent | DsyncUserCreatedEvent | DsyncUserUpdatedEvent | DsyncUserDeletedEvent | EmailVerificationCreatedEvent | InvitationCreatedEvent | MagicAuthCreatedEvent | PasswordResetCreatedEvent | PasswordResetSucceededEvent | UserCreatedEvent | UserUpdatedEvent | UserDeletedEvent | OrganizationMembershipAdded | OrganizationMembershipCreated | OrganizationMembershipDeleted | OrganizationMembershipUpdated | OrganizationMembershipRemoved | RoleCreatedEvent | RoleDeletedEvent | RoleUpdatedEvent | SessionCreatedEvent | SessionRevokedEvent | OrganizationCreatedEvent | OrganizationUpdatedEvent | OrganizationDeletedEvent | OrganizationDomainVerifiedEvent | OrganizationDomainVerificationFailedEvent | OrganizationDomainCreatedEvent | OrganizationDomainUpdatedEvent | OrganizationDomainDeletedEvent;
|
|
454
|
+
export type EventResponse = AuthenticationEmailVerificationSucceededEventResponse | AuthenticationMagicAuthFailedEventResponse | AuthenticationMagicAuthSucceededEventResponse | AuthenticationMfaSucceededEventResponse | AuthenticationOAuthFailedEventResponse | AuthenticationOAuthSucceededEventResponse | AuthenticationPasswordFailedEventResponse | AuthenticationPasswordSucceededEventResponse | AuthenticationSSOFailedEventResponse | AuthenticationSSOSucceededEventResponse | AuthenticationRadarRiskDetectedEventResponse | ConnectionActivatedEventResponse | ConnectionDeactivatedEventResponse | ConnectionDeletedEventResponse | DsyncActivatedEventResponse | DsyncDeactivatedEventResponse | DsyncDeletedEventResponse | DsyncGroupCreatedEventResponse | DsyncGroupUpdatedEventResponse | DsyncGroupDeletedEventResponse | DsyncGroupUserAddedEventResponse | DsyncGroupUserRemovedEventResponse | DsyncUserCreatedEventResponse | DsyncUserUpdatedEventResponse | DsyncUserDeletedEventResponse | EmailVerificationCreatedEventResponse | InvitationCreatedEventResponse | MagicAuthCreatedEventResponse | PasswordResetCreatedEventResponse | PasswordResetSucceededEventResponse | UserCreatedEventResponse | UserUpdatedEventResponse | UserDeletedEventResponse | OrganizationMembershipAddedResponse | OrganizationMembershipCreatedResponse | OrganizationMembershipDeletedResponse | OrganizationMembershipUpdatedResponse | OrganizationMembershipRemovedResponse | RoleCreatedEventResponse | RoleDeletedEventResponse | RoleUpdatedEventResponse | SessionCreatedEventResponse | SessionRevokedEventResponse | OrganizationCreatedResponse | OrganizationUpdatedResponse | OrganizationDeletedResponse | OrganizationDomainVerifiedEventResponse | OrganizationDomainVerificationFailedEventResponse | OrganizationDomainCreatedEventResponse | OrganizationDomainUpdatedEventResponse | OrganizationDomainDeletedEventResponse;
|
|
431
455
|
export type EventName = Event['event'];
|
|
432
456
|
export {};
|
|
@@ -87,6 +87,9 @@ const deserializeEvent = (event) => {
|
|
|
87
87
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, serializers_2.deserializeOrganization)(event.data) });
|
|
88
88
|
case 'organization_domain.verified':
|
|
89
89
|
case 'organization_domain.verification_failed':
|
|
90
|
+
case 'organization_domain.created':
|
|
91
|
+
case 'organization_domain.updated':
|
|
92
|
+
case 'organization_domain.deleted':
|
|
90
93
|
return Object.assign(Object.assign({}, eventBase), { event: event.event, data: (0, organization_domain_serializer_1.deserializeOrganizationDomain)(event.data) });
|
|
91
94
|
}
|
|
92
95
|
};
|
|
@@ -19,6 +19,8 @@ export interface OrganizationDomain {
|
|
|
19
19
|
state: OrganizationDomainState;
|
|
20
20
|
verificationToken?: string;
|
|
21
21
|
verificationStrategy: OrganizationDomainVerificationStrategy;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
updatedAt: string;
|
|
22
24
|
}
|
|
23
25
|
export interface OrganizationDomainResponse {
|
|
24
26
|
object: 'organization_domain';
|
|
@@ -28,4 +30,6 @@ export interface OrganizationDomainResponse {
|
|
|
28
30
|
state: OrganizationDomainState;
|
|
29
31
|
verification_token?: string;
|
|
30
32
|
verification_strategy: OrganizationDomainVerificationStrategy;
|
|
33
|
+
created_at: string;
|
|
34
|
+
updated_at: string;
|
|
31
35
|
}
|
|
@@ -9,5 +9,7 @@ const deserializeOrganizationDomain = (organizationDomain) => ({
|
|
|
9
9
|
state: organizationDomain.state,
|
|
10
10
|
verificationToken: organizationDomain.verification_token,
|
|
11
11
|
verificationStrategy: organizationDomain.verification_strategy,
|
|
12
|
+
createdAt: organizationDomain.created_at,
|
|
13
|
+
updatedAt: organizationDomain.updated_at,
|
|
12
14
|
});
|
|
13
15
|
exports.deserializeOrganizationDomain = deserializeOrganizationDomain;
|
package/lib/user-management/interfaces/authenticate-with-code-and-verifier-options.interface.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthenticateWithOptionsBase, SerializedAuthenticateWithPKCEBase } from './authenticate-with-options-base.interface';
|
|
2
|
+
export interface AuthenticateWithCodeAndVerifierOptions extends AuthenticateWithOptionsBase {
|
|
3
|
+
codeVerifier: string;
|
|
4
|
+
code: string;
|
|
5
|
+
invitationToken?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SerializedAuthenticateWithCodeAndVerifierOptions extends SerializedAuthenticateWithPKCEBase {
|
|
8
|
+
grant_type: 'authorization_code';
|
|
9
|
+
code_verifier: string;
|
|
10
|
+
code: string;
|
|
11
|
+
invitation_token?: string;
|
|
12
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './authenticate-with-code-options.interface';
|
|
2
|
+
export * from './authenticate-with-code-and-verifier-options.interface';
|
|
2
3
|
export * from './authenticate-with-email-verification-options.interface';
|
|
3
4
|
export * from './authenticate-with-magic-auth-options.interface';
|
|
4
5
|
export * from './authenticate-with-options-base.interface';
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./authenticate-with-code-options.interface"), exports);
|
|
18
|
+
__exportStar(require("./authenticate-with-code-and-verifier-options.interface"), exports);
|
|
18
19
|
__exportStar(require("./authenticate-with-email-verification-options.interface"), exports);
|
|
19
20
|
__exportStar(require("./authenticate-with-magic-auth-options.interface"), exports);
|
|
20
21
|
__exportStar(require("./authenticate-with-options-base.interface"), exports);
|
package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { AuthenticateWithCodeAndVerifierOptions, SerializedAuthenticateWithCodeAndVerifierOptions } from '../interfaces';
|
|
2
|
+
export declare const serializeAuthenticateWithCodeAndVerifierOptions: (options: AuthenticateWithCodeAndVerifierOptions) => SerializedAuthenticateWithCodeAndVerifierOptions;
|
package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeAuthenticateWithCodeAndVerifierOptions = void 0;
|
|
4
|
+
const serializeAuthenticateWithCodeAndVerifierOptions = (options) => ({
|
|
5
|
+
grant_type: 'authorization_code',
|
|
6
|
+
client_id: options.clientId,
|
|
7
|
+
code: options.code,
|
|
8
|
+
code_verifier: options.codeVerifier,
|
|
9
|
+
invitation_token: options.invitationToken,
|
|
10
|
+
ip_address: options.ipAddress,
|
|
11
|
+
user_agent: options.userAgent,
|
|
12
|
+
});
|
|
13
|
+
exports.serializeAuthenticateWithCodeAndVerifierOptions = serializeAuthenticateWithCodeAndVerifierOptions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './authenticate-with-code-options.serializer';
|
|
2
|
+
export * from './authenticate-with-code-and-verifier-options.serializer';
|
|
2
3
|
export * from './authenticate-with-magic-auth-options.serializer';
|
|
3
4
|
export * from './authenticate-with-password-options.serializer';
|
|
4
5
|
export * from './authenticate-with-refresh-token.options.serializer';
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./authenticate-with-code-options.serializer"), exports);
|
|
18
|
+
__exportStar(require("./authenticate-with-code-and-verifier-options.serializer"), exports);
|
|
18
19
|
__exportStar(require("./authenticate-with-magic-auth-options.serializer"), exports);
|
|
19
20
|
__exportStar(require("./authenticate-with-password-options.serializer"), exports);
|
|
20
21
|
__exportStar(require("./authenticate-with-refresh-token.options.serializer"), exports);
|
|
@@ -3,7 +3,7 @@ import { IronSessionProvider } from '../common/iron-session/iron-session-provide
|
|
|
3
3
|
import { AutoPaginatable } from '../common/utils/pagination';
|
|
4
4
|
import { Challenge } from '../mfa/interfaces';
|
|
5
5
|
import { WorkOS } from '../workos';
|
|
6
|
-
import { AuthenticateWithCodeOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithRefreshTokenOptions, AuthenticateWithTotpOptions, AuthenticationResponse, CreateMagicAuthOptions, CreatePasswordResetOptions, CreateUserOptions, EmailVerification, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, MagicAuth, PasswordReset, ResetPasswordOptions, SendMagicAuthCodeOptions, SendPasswordResetEmailOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions } from './interfaces';
|
|
6
|
+
import { AuthenticateWithCodeOptions, AuthenticateWithCodeAndVerifierOptions, AuthenticateWithMagicAuthOptions, AuthenticateWithPasswordOptions, AuthenticateWithRefreshTokenOptions, AuthenticateWithTotpOptions, AuthenticationResponse, CreateMagicAuthOptions, CreatePasswordResetOptions, CreateUserOptions, EmailVerification, EnrollAuthFactorOptions, ListAuthFactorsOptions, ListUsersOptions, MagicAuth, PasswordReset, ResetPasswordOptions, SendMagicAuthCodeOptions, SendPasswordResetEmailOptions, SendVerificationEmailOptions, UpdateUserOptions, User, VerifyEmailOptions } from './interfaces';
|
|
7
7
|
import { AuthenticateWithEmailVerificationOptions } from './interfaces/authenticate-with-email-verification-options.interface';
|
|
8
8
|
import { AuthenticateWithOrganizationSelectionOptions } from './interfaces/authenticate-with-organization-selection.interface';
|
|
9
9
|
import { AuthenticateWithSessionCookieFailedResponse, AuthenticateWithSessionCookieOptions, AuthenticateWithSessionCookieSuccessResponse, SessionCookieData } from './interfaces/authenticate-with-session-cookie.interface';
|
|
@@ -47,6 +47,7 @@ export declare class UserManagement {
|
|
|
47
47
|
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
48
48
|
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
49
49
|
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
50
|
+
authenticateWithCodeAndVerifier(payload: AuthenticateWithCodeAndVerifierOptions): Promise<AuthenticationResponse>;
|
|
50
51
|
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<AuthenticationResponse>;
|
|
51
52
|
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
52
53
|
authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
|
|
@@ -106,7 +107,7 @@ export declare class UserManagement {
|
|
|
106
107
|
acceptInvitation(invitationId: string): Promise<Invitation>;
|
|
107
108
|
revokeInvitation(invitationId: string): Promise<Invitation>;
|
|
108
109
|
revokeSession(payload: RevokeSessionOptions): Promise<void>;
|
|
109
|
-
getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, redirectUri, state, screenHint, }: UserManagementAuthorizationURLOptions): string;
|
|
110
|
+
getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, prompt, redirectUri, state, screenHint, }: UserManagementAuthorizationURLOptions): string;
|
|
110
111
|
getLogoutUrl({ sessionId, returnTo, }: {
|
|
111
112
|
sessionId: string;
|
|
112
113
|
returnTo?: string;
|
|
@@ -141,6 +141,16 @@ class UserManagement {
|
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
+
authenticateWithCodeAndVerifier(payload) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const { session } = payload, remainingPayload = __rest(payload, ["session"]);
|
|
147
|
+
const { data } = yield this.workos.post('/user_management/authenticate', (0, serializers_2.serializeAuthenticateWithCodeAndVerifierOptions)(remainingPayload));
|
|
148
|
+
return this.prepareAuthenticationResponse({
|
|
149
|
+
authenticationResponse: (0, serializers_2.deserializeAuthenticationResponse)(data),
|
|
150
|
+
session,
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
144
154
|
authenticateWithRefreshToken(payload) {
|
|
145
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
156
|
const { session } = payload, remainingPayload = __rest(payload, ["session"]);
|
|
@@ -525,7 +535,7 @@ class UserManagement {
|
|
|
525
535
|
yield this.workos.post('/user_management/sessions/revoke', (0, revoke_session_options_interface_1.serializeRevokeSessionOptions)(payload));
|
|
526
536
|
});
|
|
527
537
|
}
|
|
528
|
-
getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, redirectUri, state, screenHint, }) {
|
|
538
|
+
getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, context, clientId, domainHint, loginHint, organizationId, provider, providerScopes, prompt, redirectUri, state, screenHint, }) {
|
|
529
539
|
if (!provider && !connectionId && !organizationId) {
|
|
530
540
|
throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
|
|
531
541
|
}
|
|
@@ -546,6 +556,7 @@ class UserManagement {
|
|
|
546
556
|
login_hint: loginHint,
|
|
547
557
|
provider,
|
|
548
558
|
provider_scopes: providerScopes,
|
|
559
|
+
prompt,
|
|
549
560
|
client_id: clientId,
|
|
550
561
|
redirect_uri: redirectUri,
|
|
551
562
|
response_type: 'code',
|
|
@@ -433,6 +433,90 @@ describe('UserManagement', () => {
|
|
|
433
433
|
}));
|
|
434
434
|
});
|
|
435
435
|
});
|
|
436
|
+
describe('authenticateWithCodeAndVerifier', () => {
|
|
437
|
+
it('sends a token authentication request with required code_verifier', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
438
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
439
|
+
const resp = yield workos.userManagement.authenticateWithCodeAndVerifier({
|
|
440
|
+
clientId: 'proj_whatever',
|
|
441
|
+
code: 'auth_code_123',
|
|
442
|
+
codeVerifier: 'required_code_verifier',
|
|
443
|
+
});
|
|
444
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
445
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
446
|
+
client_id: 'proj_whatever',
|
|
447
|
+
code: 'auth_code_123',
|
|
448
|
+
code_verifier: 'required_code_verifier',
|
|
449
|
+
grant_type: 'authorization_code',
|
|
450
|
+
});
|
|
451
|
+
expect(resp).toMatchObject({
|
|
452
|
+
user: {
|
|
453
|
+
email: 'test01@example.com',
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
}));
|
|
457
|
+
it('sends a token authentication request with invitation token', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
458
|
+
(0, test_utils_1.fetchOnce)({ user: user_json_1.default });
|
|
459
|
+
const resp = yield workos.userManagement.authenticateWithCodeAndVerifier({
|
|
460
|
+
clientId: 'proj_whatever',
|
|
461
|
+
code: 'auth_code_123',
|
|
462
|
+
codeVerifier: 'required_code_verifier',
|
|
463
|
+
invitationToken: 'invitation_123',
|
|
464
|
+
});
|
|
465
|
+
expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
|
|
466
|
+
expect((0, test_utils_1.fetchBody)()).toEqual({
|
|
467
|
+
client_id: 'proj_whatever',
|
|
468
|
+
code: 'auth_code_123',
|
|
469
|
+
code_verifier: 'required_code_verifier',
|
|
470
|
+
invitation_token: 'invitation_123',
|
|
471
|
+
grant_type: 'authorization_code',
|
|
472
|
+
});
|
|
473
|
+
expect(resp).toMatchObject({
|
|
474
|
+
user: {
|
|
475
|
+
email: 'test01@example.com',
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
}));
|
|
479
|
+
describe('when sealSession = true', () => {
|
|
480
|
+
beforeEach(() => {
|
|
481
|
+
(0, test_utils_1.fetchOnce)({
|
|
482
|
+
user: user_json_1.default,
|
|
483
|
+
access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ewogICJzdWIiOiAiMTIzNDU2Nzg5MCIsCiAgIm5hbWUiOiAiSm9obiBEb2UiLAogICJpYXQiOiAxNTE2MjM5MDIyLAogICJzaWQiOiAic2Vzc2lvbl8xMjMiLAogICJvcmdfaWQiOiAib3JnXzEyMyIsCiAgInJvbGUiOiAibWVtYmVyIiwKICAicGVybWlzc2lvbnMiOiBbInBvc3RzOmNyZWF0ZSIsICJwb3N0czpkZWxldGUiXQp9.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
describe('when the cookie password is undefined', () => {
|
|
487
|
+
it('throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
488
|
+
yield expect(workos.userManagement.authenticateWithCodeAndVerifier({
|
|
489
|
+
clientId: 'proj_whatever',
|
|
490
|
+
code: 'auth_code_123',
|
|
491
|
+
codeVerifier: 'required_code_verifier',
|
|
492
|
+
session: { sealSession: true },
|
|
493
|
+
})).rejects.toThrow('Cookie password is required');
|
|
494
|
+
}));
|
|
495
|
+
});
|
|
496
|
+
describe('when successfully authenticated', () => {
|
|
497
|
+
it('returns the sealed session data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
498
|
+
const cookiePassword = 'alongcookiesecretmadefortestingsessions';
|
|
499
|
+
const response = yield workos.userManagement.authenticateWithCodeAndVerifier({
|
|
500
|
+
clientId: 'proj_whatever',
|
|
501
|
+
code: 'auth_code_123',
|
|
502
|
+
codeVerifier: 'required_code_verifier',
|
|
503
|
+
session: { sealSession: true, cookiePassword },
|
|
504
|
+
});
|
|
505
|
+
expect(response).toEqual({
|
|
506
|
+
sealedSession: expect.any(String),
|
|
507
|
+
accessToken: expect.any(String),
|
|
508
|
+
authenticationMethod: undefined,
|
|
509
|
+
impersonator: undefined,
|
|
510
|
+
organizationId: undefined,
|
|
511
|
+
refreshToken: undefined,
|
|
512
|
+
user: expect.objectContaining({
|
|
513
|
+
email: 'test01@example.com',
|
|
514
|
+
}),
|
|
515
|
+
});
|
|
516
|
+
}));
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
});
|
|
436
520
|
describe('authenticateWithRefreshToken', () => {
|
|
437
521
|
it('sends a refresh_token authentication request', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
438
522
|
(0, test_utils_1.fetchOnce)({
|
|
@@ -1674,6 +1758,29 @@ describe('UserManagement', () => {
|
|
|
1674
1758
|
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&connection_id=connection_123&login_hint=foo%40workos.com&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
|
|
1675
1759
|
});
|
|
1676
1760
|
});
|
|
1761
|
+
describe('with prompt', () => {
|
|
1762
|
+
it('generates an authorize url with the provided prompt', () => {
|
|
1763
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
1764
|
+
const url = workos.userManagement.getAuthorizationUrl({
|
|
1765
|
+
prompt: 'login',
|
|
1766
|
+
connectionId: 'connection_123',
|
|
1767
|
+
clientId: 'proj_123',
|
|
1768
|
+
redirectUri: 'example.com/auth/workos/callback',
|
|
1769
|
+
state: 'custom state',
|
|
1770
|
+
});
|
|
1771
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&connection_id=connection_123&prompt=login&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code&state=custom+state"`);
|
|
1772
|
+
});
|
|
1773
|
+
it('generates an authorize url with consent prompt', () => {
|
|
1774
|
+
const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
|
|
1775
|
+
const url = workos.userManagement.getAuthorizationUrl({
|
|
1776
|
+
prompt: 'consent',
|
|
1777
|
+
provider: 'GoogleOAuth',
|
|
1778
|
+
clientId: 'proj_123',
|
|
1779
|
+
redirectUri: 'example.com/auth/workos/callback',
|
|
1780
|
+
});
|
|
1781
|
+
expect(url).toMatchInlineSnapshot(`"https://api.workos.com/user_management/authorize?client_id=proj_123&prompt=consent&provider=GoogleOAuth&redirect_uri=example.com%2Fauth%2Fworkos%2Fcallback&response_type=code"`);
|
|
1782
|
+
});
|
|
1783
|
+
});
|
|
1677
1784
|
});
|
|
1678
1785
|
describe('getLogoutUrl', () => {
|
|
1679
1786
|
it('returns a logout url', () => {
|
package/lib/workos.js
CHANGED
|
@@ -31,7 +31,7 @@ const widgets_1 = require("./widgets/widgets");
|
|
|
31
31
|
const actions_1 = require("./actions/actions");
|
|
32
32
|
const vault_1 = require("./vault/vault");
|
|
33
33
|
const conflict_exception_1 = require("./common/exceptions/conflict.exception");
|
|
34
|
-
const VERSION = '7.
|
|
34
|
+
const VERSION = '7.59.0';
|
|
35
35
|
const DEFAULT_HOSTNAME = 'api.workos.com';
|
|
36
36
|
const HEADER_AUTHORIZATION = 'Authorization';
|
|
37
37
|
const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
|
package/package.json
CHANGED