@workos-inc/node 7.8.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.
- package/lib/user-management/interfaces/authenticate-with-code-options.interface.d.ts +2 -0
- package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +2 -0
- package/lib/user-management/serializers/authenticate-with-code-options.serializer.js +1 -0
- package/lib/user-management/user-management.d.ts +1 -1
- package/lib/user-management/user-management.js +3 -1
- package/lib/user-management/user-management.spec.js +34 -0
- package/lib/workos.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -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,
|
|
@@ -69,7 +69,7 @@ export declare class UserManagement {
|
|
|
69
69
|
sendInvitation(payload: SendInvitationOptions): Promise<Invitation>;
|
|
70
70
|
revokeInvitation(invitationId: string): Promise<Invitation>;
|
|
71
71
|
revokeSession(payload: RevokeSessionOptions): Promise<void>;
|
|
72
|
-
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;
|
|
73
73
|
getLogoutUrl({ sessionId }: {
|
|
74
74
|
sessionId: string;
|
|
75
75
|
}): string;
|
|
@@ -269,7 +269,7 @@ class UserManagement {
|
|
|
269
269
|
yield this.workos.post('/user_management/sessions/revoke', (0, revoke_session_options_interface_1.serializeRevokeSessionOptions)(payload));
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
getAuthorizationUrl({ connectionId, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }) {
|
|
272
|
+
getAuthorizationUrl({ connectionId, codeChallenge, codeChallengeMethod, clientId, domainHint, loginHint, organizationId, provider, redirectUri, state, screenHint, }) {
|
|
273
273
|
if (!provider && !connectionId && !organizationId) {
|
|
274
274
|
throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
|
|
275
275
|
}
|
|
@@ -278,6 +278,8 @@ class UserManagement {
|
|
|
278
278
|
}
|
|
279
279
|
const query = toQueryString({
|
|
280
280
|
connection_id: connectionId,
|
|
281
|
+
code_challenge: codeChallenge,
|
|
282
|
+
code_challenge_method: codeChallengeMethod,
|
|
281
283
|
organization_id: organizationId,
|
|
282
284
|
domain_hint: domainHint,
|
|
283
285
|
login_hint: loginHint,
|
|
@@ -163,6 +163,27 @@ describe('UserManagement', () => {
|
|
|
163
163
|
},
|
|
164
164
|
});
|
|
165
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
|
+
}));
|
|
166
187
|
it('deserializes authentication_method', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
167
188
|
(0, test_utils_1.fetchOnce)({
|
|
168
189
|
user: user_json_1.default,
|
|
@@ -868,6 +889,19 @@ describe('UserManagement', () => {
|
|
|
868
889
|
expect(url).toMatchSnapshot();
|
|
869
890
|
});
|
|
870
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
|
+
});
|
|
871
905
|
describe('with no custom api hostname', () => {
|
|
872
906
|
it('generates an authorize url with the default api hostname', () => {
|
|
873
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.
|
|
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