@workos-inc/node 7.56.0 → 7.57.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.
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -14,3 +14,8 @@ export interface SerializedAuthenticateWithOptionsBase {
14
14
  ip_address?: string;
15
15
  user_agent?: string;
16
16
  }
17
+ export interface SerializedAuthenticateWithPKCEBase {
18
+ client_id: string;
19
+ ip_address?: string;
20
+ user_agent?: string;
21
+ }
@@ -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);
@@ -0,0 +1,2 @@
1
+ import { AuthenticateWithCodeAndVerifierOptions, SerializedAuthenticateWithCodeAndVerifierOptions } from '../interfaces';
2
+ export declare const serializeAuthenticateWithCodeAndVerifierOptions: (options: AuthenticateWithCodeAndVerifierOptions) => SerializedAuthenticateWithCodeAndVerifierOptions;
@@ -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>;
@@ -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"]);
@@ -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)({
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.56.0';
34
+ const VERSION = '7.57.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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.56.0",
2
+ "version": "7.57.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",