@workos-inc/node 7.7.0 → 7.9.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.
@@ -1,5 +1,6 @@
1
1
  import { AuthenticateWithOptionsBase, SerializedAuthenticateWithOptionsBase } from './authenticate-with-options-base.interface';
2
2
  export interface AuthenticateWithCodeOptions extends AuthenticateWithOptionsBase {
3
+ codeVerifier?: string;
3
4
  code: string;
4
5
  invitationToken?: string;
5
6
  }
@@ -8,6 +9,7 @@ export interface AuthenticateUserWithCodeCredentials {
8
9
  }
9
10
  export interface SerializedAuthenticateWithCodeOptions extends SerializedAuthenticateWithOptionsBase {
10
11
  grant_type: 'authorization_code';
12
+ code_verifier?: string;
11
13
  code: string;
12
14
  invitation_token?: string;
13
15
  }
@@ -1,5 +1,7 @@
1
1
  export interface AuthorizationURLOptions {
2
2
  clientId: string;
3
+ codeChallenge?: string;
4
+ codeChallengeMethod?: 'S256';
3
5
  connectionId?: string;
4
6
  organizationId?: string;
5
7
  domainHint?: string;
@@ -6,6 +6,7 @@ const serializeAuthenticateWithCodeOptions = (options) => ({
6
6
  client_id: options.clientId,
7
7
  client_secret: options.clientSecret,
8
8
  code: options.code,
9
+ code_verifier: options.codeVerifier,
9
10
  invitation_token: options.invitationToken,
10
11
  ip_address: options.ipAddress,
11
12
  user_agent: options.userAgent,
@@ -64,11 +64,12 @@ export declare class UserManagement {
64
64
  deactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
65
65
  reactivateOrganizationMembership(organizationMembershipId: string): Promise<OrganizationMembership>;
66
66
  getInvitation(invitationId: string): Promise<Invitation>;
67
+ findInvitationByToken(invitationToken: string): Promise<Invitation>;
67
68
  listInvitations(options: ListInvitationsOptions): Promise<AutoPaginatable<Invitation>>;
68
69
  sendInvitation(payload: SendInvitationOptions): Promise<Invitation>;
69
70
  revokeInvitation(invitationId: string): Promise<Invitation>;
70
71
  revokeSession(payload: RevokeSessionOptions): Promise<void>;
71
- getAuthorizationUrl({ connectionId, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }: AuthorizationURLOptions): string;
72
+ getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }: AuthorizationURLOptions): string;
72
73
  getLogoutUrl({ sessionId }: {
73
74
  sessionId: string;
74
75
  }): string;
@@ -241,6 +241,12 @@ class UserManagement {
241
241
  return (0, invitation_serializer_1.deserializeInvitation)(data);
242
242
  });
243
243
  }
244
+ findInvitationByToken(invitationToken) {
245
+ return __awaiter(this, void 0, void 0, function* () {
246
+ const { data } = yield this.workos.get(`/user_management/invitations/by_token/${invitationToken}`);
247
+ return (0, invitation_serializer_1.deserializeInvitation)(data);
248
+ });
249
+ }
244
250
  listInvitations(options) {
245
251
  return __awaiter(this, void 0, void 0, function* () {
246
252
  return new pagination_1.AutoPaginatable(yield (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/user_management/invitations', invitation_serializer_1.deserializeInvitation, options ? (0, list_invitations_options_serializer_1.serializeListInvitationsOptions)(options) : undefined), (params) => (0, fetch_and_deserialize_1.fetchAndDeserialize)(this.workos, '/user_management/invitations', invitation_serializer_1.deserializeInvitation, params), options ? (0, list_invitations_options_serializer_1.serializeListInvitationsOptions)(options) : undefined);
@@ -263,7 +269,7 @@ class UserManagement {
263
269
  yield this.workos.post('/user_management/sessions/revoke', (0, revoke_session_options_interface_1.serializeRevokeSessionOptions)(payload));
264
270
  });
265
271
  }
266
- getAuthorizationUrl({ connectionId, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }) {
272
+ getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }) {
267
273
  if (!provider && !connectionId && !organizationId) {
268
274
  throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
269
275
  }
@@ -272,6 +278,8 @@ class UserManagement {
272
278
  }
273
279
  const query = toQueryString({
274
280
  connection_id: connectionId,
281
+ code_challenge: codeChallenge,
282
+ code_challenge_method: codeChallengeMethod,
275
283
  organization_id: organizationId,
276
284
  domain_hint: domainHint,
277
285
  login_hint: loginHint,
@@ -31,6 +31,7 @@ const userId = 'user_01H5JQDV7R7ATEYZDEG0W5PRYS';
31
31
  const organizationMembershipId = 'om_01H5JQDV7R7ATEYZDEG0W5PRYS';
32
32
  const emailVerificationId = 'email_verification_01H5JQDV7R7ATEYZDEG0W5PRYS';
33
33
  const invitationId = 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS';
34
+ const invitationToken = 'Z1uX3RbwcIl5fIGJJJCXXisdI';
34
35
  const magicAuthId = 'magic_auth_01H5JQDV7R7ATEYZDEG0W5PRYS';
35
36
  const passwordResetId = 'password_reset_01H5JQDV7R7ATEYZDEG0W5PRYS';
36
37
  describe('UserManagement', () => {
@@ -162,6 +163,27 @@ describe('UserManagement', () => {
162
163
  },
163
164
  });
164
165
  }));
166
+ it('sends a token authentication request when including the code_verifier', () => __awaiter(void 0, void 0, void 0, function* () {
167
+ (0, test_utils_1.fetchOnce)({ user: user_json_1.default });
168
+ const resp = yield workos.userManagement.authenticateWithCode({
169
+ clientId: 'proj_whatever',
170
+ code: 'or this',
171
+ codeVerifier: 'code_verifier_value',
172
+ });
173
+ expect((0, test_utils_1.fetchURL)()).toContain('/user_management/authenticate');
174
+ expect((0, test_utils_1.fetchBody)()).toEqual({
175
+ client_id: 'proj_whatever',
176
+ client_secret: 'sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU',
177
+ code: 'or this',
178
+ code_verifier: 'code_verifier_value',
179
+ grant_type: 'authorization_code',
180
+ });
181
+ expect(resp).toMatchObject({
182
+ user: {
183
+ email: 'test01@example.com',
184
+ },
185
+ });
186
+ }));
165
187
  it('deserializes authentication_method', () => __awaiter(void 0, void 0, void 0, function* () {
166
188
  (0, test_utils_1.fetchOnce)({
167
189
  user: user_json_1.default,
@@ -742,7 +764,21 @@ describe('UserManagement', () => {
742
764
  (0, test_utils_1.fetchOnce)(invitation_json_1.default);
743
765
  const invitation = yield workos.userManagement.getInvitation(invitationId);
744
766
  expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/invitations/${invitationId}`);
745
- expect(invitation).toMatchObject({});
767
+ expect(invitation).toMatchObject({
768
+ object: 'invitation',
769
+ id: invitationId,
770
+ });
771
+ }));
772
+ });
773
+ describe('findInvitationByToken', () => {
774
+ it('sends a find invitation by token request', () => __awaiter(void 0, void 0, void 0, function* () {
775
+ (0, test_utils_1.fetchOnce)(invitation_json_1.default);
776
+ const invitation = yield workos.userManagement.findInvitationByToken(invitationToken);
777
+ expect((0, test_utils_1.fetchURL)()).toContain(`/user_management/invitations/by_token/${invitationToken}`);
778
+ expect(invitation).toMatchObject({
779
+ object: 'invitation',
780
+ token: invitationToken,
781
+ });
746
782
  }));
747
783
  });
748
784
  describe('listInvitations', () => {
@@ -853,6 +889,19 @@ describe('UserManagement', () => {
853
889
  expect(url).toMatchSnapshot();
854
890
  });
855
891
  });
892
+ describe('with a code_challenge and code_challenge_method', () => {
893
+ it('generates an authorize url', () => {
894
+ const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
895
+ const url = workos.userManagement.getAuthorizationUrl({
896
+ provider: 'authkit',
897
+ clientId: 'proj_123',
898
+ redirectUri: 'example.com/auth/workos/callback',
899
+ codeChallenge: 'code_challenge_value',
900
+ codeChallengeMethod: 'S256',
901
+ });
902
+ expect(url).toMatchSnapshot();
903
+ });
904
+ });
856
905
  describe('with no custom api hostname', () => {
857
906
  it('generates an authorize url with the default api hostname', () => {
858
907
  const workos = new workos_1.WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');
package/lib/workos.js CHANGED
@@ -24,7 +24,7 @@ const audit_logs_1 = require("./audit-logs/audit-logs");
24
24
  const user_management_1 = require("./user-management/user-management");
25
25
  const bad_request_exception_1 = require("./common/exceptions/bad-request.exception");
26
26
  const fetch_client_1 = require("./common/utils/fetch-client");
27
- const VERSION = '7.7.0';
27
+ const VERSION = '7.9.0';
28
28
  const DEFAULT_HOSTNAME = 'api.workos.com';
29
29
  class WorkOS {
30
30
  constructor(key, options = {}) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "7.7.0",
2
+ "version": "7.9.0",
3
3
  "name": "@workos-inc/node",
4
4
  "author": "WorkOS",
5
5
  "description": "A Node wrapper for the WorkOS API",