@workos-inc/node 8.0.0-rc.7 → 8.0.0-rc.8
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/README.md +54 -0
- package/lib/api-keys/api-keys.cjs +3 -0
- package/lib/api-keys/api-keys.cjs.map +1 -1
- package/lib/api-keys/api-keys.d.cts +2 -1
- package/lib/api-keys/api-keys.d.ts +2 -1
- package/lib/api-keys/api-keys.js +3 -0
- package/lib/api-keys/api-keys.js.map +1 -1
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.cjs +0 -0
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.d.cts +16 -0
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.d.ts +16 -0
- package/lib/api-keys/interfaces/create-organization-api-key-options.interface.js +1 -0
- package/lib/api-keys/interfaces/created-api-key.interface.cjs +0 -0
- package/lib/api-keys/interfaces/created-api-key.interface.d.cts +34 -0
- package/lib/api-keys/interfaces/created-api-key.interface.d.ts +34 -0
- package/lib/api-keys/interfaces/created-api-key.interface.js +1 -0
- package/lib/api-keys/interfaces/index.cjs +0 -0
- package/lib/api-keys/interfaces/index.d.cts +6 -0
- package/lib/api-keys/interfaces/index.d.ts +6 -0
- package/lib/api-keys/interfaces/index.js +1 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.cjs +0 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.d.cts +9 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.d.ts +9 -0
- package/lib/api-keys/interfaces/list-organization-api-keys-options.interface.js +1 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.cjs +12 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.cjs.map +1 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.d.cts +7 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.d.ts +7 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.js +11 -0
- package/lib/api-keys/serializers/create-organization-api-key-options.serializer.js.map +1 -0
- package/lib/api-keys/serializers/created-api-key.serializer.cjs +20 -0
- package/lib/api-keys/serializers/created-api-key.serializer.cjs.map +1 -0
- package/lib/api-keys/serializers/created-api-key.serializer.d.cts +7 -0
- package/lib/api-keys/serializers/created-api-key.serializer.d.ts +7 -0
- package/lib/api-keys/serializers/created-api-key.serializer.js +19 -0
- package/lib/api-keys/serializers/created-api-key.serializer.js.map +1 -0
- package/lib/api-keys/serializers/index.cjs +9 -0
- package/lib/api-keys/serializers/index.d.cts +5 -0
- package/lib/api-keys/serializers/index.d.ts +5 -0
- package/lib/api-keys/serializers/index.js +6 -0
- package/lib/common/exceptions/api-key-required.exception.cjs +15 -0
- package/lib/common/exceptions/api-key-required.exception.cjs.map +1 -0
- package/lib/common/exceptions/api-key-required.exception.d.cts +10 -0
- package/lib/common/exceptions/api-key-required.exception.d.ts +10 -0
- package/lib/common/exceptions/api-key-required.exception.js +14 -0
- package/lib/common/exceptions/api-key-required.exception.js.map +1 -0
- package/lib/common/exceptions/index.cjs +2 -0
- package/lib/common/exceptions/index.d.cts +2 -1
- package/lib/common/exceptions/index.d.ts +2 -1
- package/lib/common/exceptions/index.js +2 -1
- package/lib/common/interfaces/event.interface.d.cts +28 -3
- package/lib/common/interfaces/event.interface.d.ts +28 -3
- package/lib/common/interfaces/get-options.interface.d.cts +2 -0
- package/lib/common/interfaces/get-options.interface.d.ts +2 -0
- package/lib/common/interfaces/index.d.cts +2 -2
- package/lib/common/interfaces/index.d.ts +2 -2
- package/lib/common/interfaces/post-options.interface.d.cts +2 -0
- package/lib/common/interfaces/post-options.interface.d.ts +2 -0
- package/lib/common/interfaces/put-options.interface.d.cts +2 -0
- package/lib/common/interfaces/put-options.interface.d.ts +2 -0
- package/lib/common/interfaces/workos-options.interface.d.cts +1 -0
- package/lib/common/interfaces/workos-options.interface.d.ts +1 -0
- package/lib/common/net/http-client.cjs.map +1 -1
- package/lib/common/net/http-client.js.map +1 -1
- package/lib/common/serializers/event.serializer.cjs +13 -5
- package/lib/common/serializers/event.serializer.cjs.map +1 -1
- package/lib/common/serializers/event.serializer.js +13 -5
- package/lib/common/serializers/event.serializer.js.map +1 -1
- package/lib/directory-sync/directory-sync.cjs +1 -1
- package/lib/directory-sync/directory-sync.js +1 -1
- package/lib/factory.cjs +10 -0
- package/lib/factory.cjs.map +1 -0
- package/lib/factory.d.cts +83 -0
- package/lib/factory.d.ts +83 -0
- package/lib/factory.js +10 -0
- package/lib/factory.js.map +1 -0
- package/lib/feature-flags/feature-flags.cjs +37 -0
- package/lib/feature-flags/feature-flags.cjs.map +1 -0
- package/lib/feature-flags/feature-flags.d.cts +21 -0
- package/lib/feature-flags/feature-flags.d.ts +21 -0
- package/lib/feature-flags/feature-flags.js +37 -0
- package/lib/feature-flags/feature-flags.js.map +1 -0
- package/lib/feature-flags/interfaces/add-flag-target-options.interface.cjs +0 -0
- package/lib/feature-flags/interfaces/add-flag-target-options.interface.d.cts +8 -0
- package/lib/feature-flags/interfaces/add-flag-target-options.interface.d.ts +8 -0
- package/lib/feature-flags/interfaces/add-flag-target-options.interface.js +1 -0
- package/lib/feature-flags/interfaces/feature-flag.interface.d.cts +8 -2
- package/lib/feature-flags/interfaces/feature-flag.interface.d.ts +8 -2
- package/lib/feature-flags/interfaces/index.d.cts +4 -1
- package/lib/feature-flags/interfaces/index.d.ts +4 -1
- package/lib/feature-flags/interfaces/list-feature-flags-options.interface.cjs +0 -0
- package/lib/feature-flags/interfaces/list-feature-flags-options.interface.d.cts +7 -0
- package/lib/feature-flags/interfaces/list-feature-flags-options.interface.d.ts +7 -0
- package/lib/feature-flags/interfaces/list-feature-flags-options.interface.js +1 -0
- package/lib/feature-flags/interfaces/remove-flag-target-options.interface.cjs +0 -0
- package/lib/feature-flags/interfaces/remove-flag-target-options.interface.d.cts +8 -0
- package/lib/feature-flags/interfaces/remove-flag-target-options.interface.d.ts +8 -0
- package/lib/feature-flags/interfaces/remove-flag-target-options.interface.js +1 -0
- package/lib/feature-flags/serializers/feature-flag.serializer.cjs +3 -0
- package/lib/feature-flags/serializers/feature-flag.serializer.cjs.map +1 -1
- package/lib/feature-flags/serializers/feature-flag.serializer.js +3 -0
- package/lib/feature-flags/serializers/feature-flag.serializer.js.map +1 -1
- package/lib/feature-flags/serializers/index.cjs +3 -0
- package/lib/feature-flags/serializers/index.d.cts +2 -0
- package/lib/feature-flags/serializers/index.d.ts +2 -0
- package/lib/feature-flags/serializers/index.js +3 -0
- package/lib/fga/serializers/query-result.serializer.cjs.map +1 -1
- package/lib/fga/serializers/query-result.serializer.js.map +1 -1
- package/lib/index.cjs +18 -9
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +18 -5
- package/lib/index.d.ts +18 -5
- package/lib/index.js +16 -10
- package/lib/index.js.map +1 -1
- package/lib/index.worker.cjs +15 -9
- package/lib/index.worker.cjs.map +1 -1
- package/lib/index.worker.d.cts +10 -5
- package/lib/index.worker.d.ts +10 -5
- package/lib/index.worker.js +13 -10
- package/lib/index.worker.js.map +1 -1
- package/lib/organizations/organizations.cjs +14 -2
- package/lib/organizations/organizations.cjs.map +1 -1
- package/lib/organizations/organizations.d.cts +6 -0
- package/lib/organizations/organizations.d.ts +6 -0
- package/lib/organizations/organizations.js +14 -2
- package/lib/organizations/organizations.js.map +1 -1
- package/lib/organizations/serializers/index.cjs +1 -1
- package/lib/organizations/serializers/index.js +1 -1
- package/lib/pkce/pkce.cjs +54 -0
- package/lib/pkce/pkce.cjs.map +1 -0
- package/lib/pkce/pkce.d.cts +38 -0
- package/lib/pkce/pkce.d.ts +38 -0
- package/lib/pkce/pkce.js +53 -0
- package/lib/pkce/pkce.js.map +1 -0
- package/lib/sso/interfaces/authorization-url-options.interface.d.cts +34 -8
- package/lib/sso/interfaces/authorization-url-options.interface.d.ts +34 -8
- package/lib/sso/interfaces/get-profile-and-token-options.interface.d.cts +6 -0
- package/lib/sso/interfaces/get-profile-and-token-options.interface.d.ts +6 -0
- package/lib/sso/interfaces/index.d.cts +2 -2
- package/lib/sso/interfaces/index.d.ts +2 -2
- package/lib/sso/sso.cjs +90 -8
- package/lib/sso/sso.cjs.map +1 -1
- package/lib/sso/sso.d.cts +41 -2
- package/lib/sso/sso.d.ts +41 -2
- package/lib/sso/sso.js +90 -8
- package/lib/sso/sso.js.map +1 -1
- package/lib/user-management/interfaces/authenticate-with-code-and-verifier-options.interface.d.cts +2 -2
- package/lib/user-management/interfaces/authenticate-with-code-and-verifier-options.interface.d.ts +2 -2
- package/lib/user-management/interfaces/authenticate-with-options-base.interface.d.cts +19 -3
- package/lib/user-management/interfaces/authenticate-with-options-base.interface.d.ts +19 -3
- package/lib/user-management/interfaces/authenticate-with-refresh-token-public-client-options.interface.cjs +0 -0
- package/lib/user-management/interfaces/authenticate-with-refresh-token-public-client-options.interface.d.cts +16 -0
- package/lib/user-management/interfaces/authenticate-with-refresh-token-public-client-options.interface.d.ts +16 -0
- package/lib/user-management/interfaces/authenticate-with-refresh-token-public-client-options.interface.js +1 -0
- package/lib/user-management/interfaces/authorization-url-options.interface.d.cts +30 -5
- package/lib/user-management/interfaces/authorization-url-options.interface.d.ts +30 -5
- package/lib/user-management/interfaces/index.d.cts +5 -3
- package/lib/user-management/interfaces/index.d.ts +5 -3
- package/lib/user-management/interfaces/logout-url-options.interface.cjs +0 -0
- package/lib/user-management/interfaces/logout-url-options.interface.d.cts +8 -0
- package/lib/user-management/interfaces/logout-url-options.interface.d.ts +8 -0
- package/lib/user-management/interfaces/logout-url-options.interface.js +1 -0
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-code-and-verifier-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-code-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-code-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-code-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-code-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-email-verification.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-email-verification.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-email-verification.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-email-verification.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-magic-auth-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-magic-auth-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-magic-auth-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-magic-auth-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-organization-selection-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-password-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-password-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-password-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-password-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.cjs +14 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.cjs.map +1 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.d.cts +8 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.d.ts +8 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.js +13 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token-public-client-options.serializer.js.map +1 -0
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-refresh-token.options.serializer.js.map +1 -1
- package/lib/user-management/serializers/authenticate-with-totp-options.serializer.cjs.map +1 -1
- package/lib/user-management/serializers/authenticate-with-totp-options.serializer.d.cts +2 -1
- package/lib/user-management/serializers/authenticate-with-totp-options.serializer.d.ts +2 -1
- package/lib/user-management/serializers/authenticate-with-totp-options.serializer.js.map +1 -1
- package/lib/user-management/serializers/index.cjs +2 -0
- package/lib/user-management/serializers/index.d.cts +2 -1
- package/lib/user-management/serializers/index.d.ts +2 -1
- package/lib/user-management/serializers/index.js +2 -1
- package/lib/user-management/session.cjs +3 -10
- package/lib/user-management/session.cjs.map +1 -1
- package/lib/user-management/session.js +3 -10
- package/lib/user-management/session.js.map +1 -1
- package/lib/user-management/user-management.cjs +186 -31
- package/lib/user-management/user-management.cjs.map +1 -1
- package/lib/user-management/user-management.d.cts +71 -2
- package/lib/user-management/user-management.d.ts +71 -2
- package/lib/user-management/user-management.js +186 -31
- package/lib/user-management/user-management.js.map +1 -1
- package/lib/vault/vault.cjs +4 -0
- package/lib/vault/vault.cjs.map +1 -1
- package/lib/vault/vault.d.cts +1 -0
- package/lib/vault/vault.d.ts +1 -0
- package/lib/vault/vault.js +4 -0
- package/lib/vault/vault.js.map +1 -1
- package/lib/webhooks/webhooks.cjs +1 -1
- package/lib/webhooks/webhooks.js +1 -1
- package/lib/workos.cjs +68 -26
- package/lib/workos.cjs.map +1 -1
- package/lib/workos.d.cts +37 -8
- package/lib/workos.d.ts +37 -8
- package/lib/workos.js +68 -26
- package/lib/workos.js.map +1 -1
- package/package.json +4 -21
- package/lib/_virtual/rolldown_runtime.cjs +0 -19
- package/lib/_virtual/rolldown_runtime.js +0 -18
- package/lib/client/index.cjs +0 -15
- package/lib/client/index.d.cts +0 -3
- package/lib/client/index.d.ts +0 -3
- package/lib/client/index.js +0 -4
- package/lib/client/sso.cjs +0 -40
- package/lib/client/sso.cjs.map +0 -1
- package/lib/client/sso.d.cts +0 -21
- package/lib/client/sso.d.ts +0 -21
- package/lib/client/sso.js +0 -34
- package/lib/client/sso.js.map +0 -1
- package/lib/client/user-management.cjs +0 -80
- package/lib/client/user-management.cjs.map +0 -1
- package/lib/client/user-management.d.cts +0 -58
- package/lib/client/user-management.d.ts +0 -58
- package/lib/client/user-management.js +0 -72
- package/lib/client/user-management.js.map +0 -1
- package/lib/index.client.cjs +0 -15
- package/lib/index.client.d.cts +0 -3
- package/lib/index.client.d.ts +0 -3
- package/lib/index.client.js +0 -4
|
@@ -10,7 +10,7 @@ import { User } from "./interfaces/user.interface.cjs";
|
|
|
10
10
|
import { AuthenticationResponse } from "./interfaces/authentication-response.interface.cjs";
|
|
11
11
|
import { AuthenticateWithSessionCookieFailedResponse, AuthenticateWithSessionCookieOptions, AuthenticateWithSessionCookieSuccessResponse, SessionCookieData } from "./interfaces/authenticate-with-session-cookie.interface.cjs";
|
|
12
12
|
import { AuthenticateWithTotpOptions } from "./interfaces/authenticate-with-totp-options.interface.cjs";
|
|
13
|
-
import { UserManagementAuthorizationURLOptions } from "./interfaces/authorization-url-options.interface.cjs";
|
|
13
|
+
import { PKCEAuthorizationURLResult, UserManagementAuthorizationURLOptions } from "./interfaces/authorization-url-options.interface.cjs";
|
|
14
14
|
import { CreateMagicAuthOptions } from "./interfaces/create-magic-auth-options.interface.cjs";
|
|
15
15
|
import { CreateOrganizationMembershipOptions } from "./interfaces/create-organization-membership-options.interface.cjs";
|
|
16
16
|
import { CreatePasswordResetOptions } from "./interfaces/create-password-reset-options.interface.cjs";
|
|
@@ -27,6 +27,7 @@ import { ListOrganizationMembershipsOptions, SerializedListOrganizationMembershi
|
|
|
27
27
|
import { ListSessionsOptions, SerializedListSessionsOptions } from "./interfaces/list-sessions-options.interface.cjs";
|
|
28
28
|
import { ListUserFeatureFlagsOptions } from "./interfaces/list-user-feature-flags-options.interface.cjs";
|
|
29
29
|
import { ListUsersOptions, SerializedListUsersOptions } from "./interfaces/list-users-options.interface.cjs";
|
|
30
|
+
import { LogoutURLOptions } from "./interfaces/logout-url-options.interface.cjs";
|
|
30
31
|
import { MagicAuth } from "./interfaces/magic-auth.interface.cjs";
|
|
31
32
|
import { PasswordReset } from "./interfaces/password-reset.interface.cjs";
|
|
32
33
|
import { ResetPasswordOptions } from "./interfaces/reset-password-options.interface.cjs";
|
|
@@ -40,7 +41,6 @@ import { VerifyEmailOptions } from "./interfaces/verify-email-options.interface.
|
|
|
40
41
|
import { AutoPaginatable } from "../common/utils/pagination.cjs";
|
|
41
42
|
import { FeatureFlag } from "../feature-flags/interfaces/feature-flag.interface.cjs";
|
|
42
43
|
import { Challenge } from "../mfa/interfaces/challenge.interface.cjs";
|
|
43
|
-
import { LogoutURLOptions } from "../client/user-management.cjs";
|
|
44
44
|
import { SessionHandlerOptions } from "./interfaces/session-handler-options.interface.cjs";
|
|
45
45
|
import { CookieSession } from "./session.cjs";
|
|
46
46
|
import { WorkOS } from "../workos.cjs";
|
|
@@ -52,6 +52,11 @@ declare class UserManagement {
|
|
|
52
52
|
private _jwks;
|
|
53
53
|
clientId: string | undefined;
|
|
54
54
|
constructor(workos: WorkOS);
|
|
55
|
+
/**
|
|
56
|
+
* Resolve clientId from method options or fall back to constructor-provided value.
|
|
57
|
+
* @throws TypeError if clientId is not available from either source
|
|
58
|
+
*/
|
|
59
|
+
private resolveClientId;
|
|
55
60
|
getJWKS(): Promise<ReturnType<typeof jose0.createRemoteJWKSet> | undefined>;
|
|
56
61
|
/**
|
|
57
62
|
* Loads a sealed session using the provided session data and cookie password.
|
|
@@ -71,8 +76,35 @@ declare class UserManagement {
|
|
|
71
76
|
createUser(payload: CreateUserOptions): Promise<User>;
|
|
72
77
|
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
73
78
|
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Exchange an authorization code for tokens.
|
|
81
|
+
*
|
|
82
|
+
* Auto-detects public vs confidential client mode:
|
|
83
|
+
* - If codeVerifier is provided: Uses PKCE flow (public client)
|
|
84
|
+
* - If no codeVerifier: Uses client_secret from API key (confidential client)
|
|
85
|
+
* - If both: Uses both client_secret AND codeVerifier (confidential client with PKCE)
|
|
86
|
+
*
|
|
87
|
+
* Using PKCE with confidential clients is recommended by OAuth 2.1 for defense
|
|
88
|
+
* in depth and provides additional CSRF protection on the authorization flow.
|
|
89
|
+
*
|
|
90
|
+
* @throws Error if neither codeVerifier nor API key is available
|
|
91
|
+
*/
|
|
74
92
|
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Exchange an authorization code for tokens using PKCE (public client flow).
|
|
95
|
+
* Use this instead of authenticateWithCode() when the client cannot securely
|
|
96
|
+
* store a client_secret (browser, mobile, CLI, desktop apps).
|
|
97
|
+
*
|
|
98
|
+
* @param payload.clientId - Your WorkOS client ID
|
|
99
|
+
* @param payload.code - The authorization code from the OAuth callback
|
|
100
|
+
* @param payload.codeVerifier - The PKCE code verifier used to generate the code challenge
|
|
101
|
+
*/
|
|
75
102
|
authenticateWithCodeAndVerifier(payload: AuthenticateWithCodeAndVerifierOptions): Promise<AuthenticationResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Refresh an access token using a refresh token.
|
|
105
|
+
* Automatically detects public client mode - if no API key is configured,
|
|
106
|
+
* omits client_secret from the request.
|
|
107
|
+
*/
|
|
76
108
|
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<AuthenticationResponse>;
|
|
77
109
|
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
78
110
|
authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
|
|
@@ -132,7 +164,44 @@ declare class UserManagement {
|
|
|
132
164
|
revokeInvitation(invitationId: string): Promise<Invitation>;
|
|
133
165
|
resendInvitation(invitationId: string): Promise<Invitation>;
|
|
134
166
|
revokeSession(payload: RevokeSessionOptions): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Generate an OAuth 2.0 authorization URL.
|
|
169
|
+
*
|
|
170
|
+
* For public clients (browser, mobile, CLI), include PKCE parameters:
|
|
171
|
+
* - Generate PKCE using workos.pkce.generate()
|
|
172
|
+
* - Pass codeChallenge and codeChallengeMethod here
|
|
173
|
+
* - Store codeVerifier and pass to authenticateWithCode() later
|
|
174
|
+
*
|
|
175
|
+
* Or use getAuthorizationUrlWithPKCE() which handles PKCE automatically.
|
|
176
|
+
*/
|
|
135
177
|
getAuthorizationUrl(options: UserManagementAuthorizationURLOptions): string;
|
|
178
|
+
/**
|
|
179
|
+
* Generate an OAuth 2.0 authorization URL with automatic PKCE.
|
|
180
|
+
*
|
|
181
|
+
* This method generates PKCE parameters internally and returns them along with
|
|
182
|
+
* the authorization URL. Use this for public clients (CLI apps, Electron, mobile)
|
|
183
|
+
* that cannot securely store a client secret.
|
|
184
|
+
*
|
|
185
|
+
* @returns Object containing url, state, and codeVerifier
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const { url, state, codeVerifier } = await workos.userManagement.getAuthorizationUrlWithPKCE({
|
|
190
|
+
* provider: 'authkit',
|
|
191
|
+
* clientId: 'client_123',
|
|
192
|
+
* redirectUri: 'myapp://callback',
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* // Store state and codeVerifier securely, then redirect user to url
|
|
196
|
+
* // After callback, exchange the code:
|
|
197
|
+
* const response = await workos.userManagement.authenticateWithCode({
|
|
198
|
+
* code: authorizationCode,
|
|
199
|
+
* codeVerifier,
|
|
200
|
+
* clientId: 'client_123',
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
getAuthorizationUrlWithPKCE(options: Omit<UserManagementAuthorizationURLOptions, 'codeChallenge' | 'codeChallengeMethod' | 'state'>): Promise<PKCEAuthorizationURLResult>;
|
|
136
205
|
getLogoutUrl(options: LogoutURLOptions): string;
|
|
137
206
|
getJwksUrl(clientId: string): string;
|
|
138
207
|
}
|
|
@@ -10,7 +10,7 @@ import { User } from "./interfaces/user.interface.js";
|
|
|
10
10
|
import { AuthenticationResponse } from "./interfaces/authentication-response.interface.js";
|
|
11
11
|
import { AuthenticateWithSessionCookieFailedResponse, AuthenticateWithSessionCookieOptions, AuthenticateWithSessionCookieSuccessResponse, SessionCookieData } from "./interfaces/authenticate-with-session-cookie.interface.js";
|
|
12
12
|
import { AuthenticateWithTotpOptions } from "./interfaces/authenticate-with-totp-options.interface.js";
|
|
13
|
-
import { UserManagementAuthorizationURLOptions } from "./interfaces/authorization-url-options.interface.js";
|
|
13
|
+
import { PKCEAuthorizationURLResult, UserManagementAuthorizationURLOptions } from "./interfaces/authorization-url-options.interface.js";
|
|
14
14
|
import { CreateMagicAuthOptions } from "./interfaces/create-magic-auth-options.interface.js";
|
|
15
15
|
import { CreateOrganizationMembershipOptions } from "./interfaces/create-organization-membership-options.interface.js";
|
|
16
16
|
import { CreatePasswordResetOptions } from "./interfaces/create-password-reset-options.interface.js";
|
|
@@ -27,6 +27,7 @@ import { ListOrganizationMembershipsOptions, SerializedListOrganizationMembershi
|
|
|
27
27
|
import { ListSessionsOptions, SerializedListSessionsOptions } from "./interfaces/list-sessions-options.interface.js";
|
|
28
28
|
import { ListUserFeatureFlagsOptions } from "./interfaces/list-user-feature-flags-options.interface.js";
|
|
29
29
|
import { ListUsersOptions, SerializedListUsersOptions } from "./interfaces/list-users-options.interface.js";
|
|
30
|
+
import { LogoutURLOptions } from "./interfaces/logout-url-options.interface.js";
|
|
30
31
|
import { MagicAuth } from "./interfaces/magic-auth.interface.js";
|
|
31
32
|
import { PasswordReset } from "./interfaces/password-reset.interface.js";
|
|
32
33
|
import { ResetPasswordOptions } from "./interfaces/reset-password-options.interface.js";
|
|
@@ -40,7 +41,6 @@ import { VerifyEmailOptions } from "./interfaces/verify-email-options.interface.
|
|
|
40
41
|
import { AutoPaginatable } from "../common/utils/pagination.js";
|
|
41
42
|
import { FeatureFlag } from "../feature-flags/interfaces/feature-flag.interface.js";
|
|
42
43
|
import { Challenge } from "../mfa/interfaces/challenge.interface.js";
|
|
43
|
-
import { LogoutURLOptions } from "../client/user-management.js";
|
|
44
44
|
import { SessionHandlerOptions } from "./interfaces/session-handler-options.interface.js";
|
|
45
45
|
import { CookieSession } from "./session.js";
|
|
46
46
|
import { WorkOS } from "../workos.js";
|
|
@@ -52,6 +52,11 @@ declare class UserManagement {
|
|
|
52
52
|
private _jwks;
|
|
53
53
|
clientId: string | undefined;
|
|
54
54
|
constructor(workos: WorkOS);
|
|
55
|
+
/**
|
|
56
|
+
* Resolve clientId from method options or fall back to constructor-provided value.
|
|
57
|
+
* @throws TypeError if clientId is not available from either source
|
|
58
|
+
*/
|
|
59
|
+
private resolveClientId;
|
|
55
60
|
getJWKS(): Promise<ReturnType<typeof jose0.createRemoteJWKSet> | undefined>;
|
|
56
61
|
/**
|
|
57
62
|
* Loads a sealed session using the provided session data and cookie password.
|
|
@@ -71,8 +76,35 @@ declare class UserManagement {
|
|
|
71
76
|
createUser(payload: CreateUserOptions): Promise<User>;
|
|
72
77
|
authenticateWithMagicAuth(payload: AuthenticateWithMagicAuthOptions): Promise<AuthenticationResponse>;
|
|
73
78
|
authenticateWithPassword(payload: AuthenticateWithPasswordOptions): Promise<AuthenticationResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Exchange an authorization code for tokens.
|
|
81
|
+
*
|
|
82
|
+
* Auto-detects public vs confidential client mode:
|
|
83
|
+
* - If codeVerifier is provided: Uses PKCE flow (public client)
|
|
84
|
+
* - If no codeVerifier: Uses client_secret from API key (confidential client)
|
|
85
|
+
* - If both: Uses both client_secret AND codeVerifier (confidential client with PKCE)
|
|
86
|
+
*
|
|
87
|
+
* Using PKCE with confidential clients is recommended by OAuth 2.1 for defense
|
|
88
|
+
* in depth and provides additional CSRF protection on the authorization flow.
|
|
89
|
+
*
|
|
90
|
+
* @throws Error if neither codeVerifier nor API key is available
|
|
91
|
+
*/
|
|
74
92
|
authenticateWithCode(payload: AuthenticateWithCodeOptions): Promise<AuthenticationResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Exchange an authorization code for tokens using PKCE (public client flow).
|
|
95
|
+
* Use this instead of authenticateWithCode() when the client cannot securely
|
|
96
|
+
* store a client_secret (browser, mobile, CLI, desktop apps).
|
|
97
|
+
*
|
|
98
|
+
* @param payload.clientId - Your WorkOS client ID
|
|
99
|
+
* @param payload.code - The authorization code from the OAuth callback
|
|
100
|
+
* @param payload.codeVerifier - The PKCE code verifier used to generate the code challenge
|
|
101
|
+
*/
|
|
75
102
|
authenticateWithCodeAndVerifier(payload: AuthenticateWithCodeAndVerifierOptions): Promise<AuthenticationResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Refresh an access token using a refresh token.
|
|
105
|
+
* Automatically detects public client mode - if no API key is configured,
|
|
106
|
+
* omits client_secret from the request.
|
|
107
|
+
*/
|
|
76
108
|
authenticateWithRefreshToken(payload: AuthenticateWithRefreshTokenOptions): Promise<AuthenticationResponse>;
|
|
77
109
|
authenticateWithTotp(payload: AuthenticateWithTotpOptions): Promise<AuthenticationResponse>;
|
|
78
110
|
authenticateWithEmailVerification(payload: AuthenticateWithEmailVerificationOptions): Promise<AuthenticationResponse>;
|
|
@@ -132,7 +164,44 @@ declare class UserManagement {
|
|
|
132
164
|
revokeInvitation(invitationId: string): Promise<Invitation>;
|
|
133
165
|
resendInvitation(invitationId: string): Promise<Invitation>;
|
|
134
166
|
revokeSession(payload: RevokeSessionOptions): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Generate an OAuth 2.0 authorization URL.
|
|
169
|
+
*
|
|
170
|
+
* For public clients (browser, mobile, CLI), include PKCE parameters:
|
|
171
|
+
* - Generate PKCE using workos.pkce.generate()
|
|
172
|
+
* - Pass codeChallenge and codeChallengeMethod here
|
|
173
|
+
* - Store codeVerifier and pass to authenticateWithCode() later
|
|
174
|
+
*
|
|
175
|
+
* Or use getAuthorizationUrlWithPKCE() which handles PKCE automatically.
|
|
176
|
+
*/
|
|
135
177
|
getAuthorizationUrl(options: UserManagementAuthorizationURLOptions): string;
|
|
178
|
+
/**
|
|
179
|
+
* Generate an OAuth 2.0 authorization URL with automatic PKCE.
|
|
180
|
+
*
|
|
181
|
+
* This method generates PKCE parameters internally and returns them along with
|
|
182
|
+
* the authorization URL. Use this for public clients (CLI apps, Electron, mobile)
|
|
183
|
+
* that cannot securely store a client secret.
|
|
184
|
+
*
|
|
185
|
+
* @returns Object containing url, state, and codeVerifier
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const { url, state, codeVerifier } = await workos.userManagement.getAuthorizationUrlWithPKCE({
|
|
190
|
+
* provider: 'authkit',
|
|
191
|
+
* clientId: 'client_123',
|
|
192
|
+
* redirectUri: 'myapp://callback',
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* // Store state and codeVerifier securely, then redirect user to url
|
|
196
|
+
* // After callback, exchange the code:
|
|
197
|
+
* const response = await workos.userManagement.authenticateWithCode({
|
|
198
|
+
* code: authorizationCode,
|
|
199
|
+
* codeVerifier,
|
|
200
|
+
* clientId: 'client_123',
|
|
201
|
+
* });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
getAuthorizationUrlWithPKCE(options: Omit<UserManagementAuthorizationURLOptions, 'codeChallenge' | 'codeChallengeMethod' | 'state'>): Promise<PKCEAuthorizationURLResult>;
|
|
136
205
|
getLogoutUrl(options: LogoutURLOptions): string;
|
|
137
206
|
getJwksUrl(clientId: string): string;
|
|
138
207
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AutoPaginatable } from "../common/utils/pagination.js";
|
|
2
2
|
import { serializeAuthenticateWithCodeOptions } from "./serializers/authenticate-with-code-options.serializer.js";
|
|
3
3
|
import { serializeAuthenticateWithCodeAndVerifierOptions } from "./serializers/authenticate-with-code-and-verifier-options.serializer.js";
|
|
4
4
|
import { serializeAuthenticateWithMagicAuthOptions } from "./serializers/authenticate-with-magic-auth-options.serializer.js";
|
|
5
5
|
import { serializeAuthenticateWithPasswordOptions } from "./serializers/authenticate-with-password-options.serializer.js";
|
|
6
6
|
import { serializeAuthenticateWithRefreshTokenOptions } from "./serializers/authenticate-with-refresh-token.options.serializer.js";
|
|
7
|
+
import { serializeAuthenticateWithRefreshTokenPublicClientOptions } from "./serializers/authenticate-with-refresh-token-public-client-options.serializer.js";
|
|
7
8
|
import { serializeAuthenticateWithTotpOptions } from "./serializers/authenticate-with-totp-options.serializer.js";
|
|
8
9
|
import { deserializeUser } from "./serializers/user.serializer.js";
|
|
9
10
|
import { deserializeAuthenticationResponse } from "./serializers/authentication-response.serializer.js";
|
|
@@ -21,9 +22,9 @@ import { deserializeSession } from "./serializers/session.serializer.js";
|
|
|
21
22
|
import { serializeCreateUserOptions } from "./serializers/create-user-options.serializer.js";
|
|
22
23
|
import { serializeUpdateUserOptions } from "./serializers/update-user-options.serializer.js";
|
|
23
24
|
import { deserializeOrganizationMembership } from "./serializers/organization-membership.serializer.js";
|
|
24
|
-
import { AutoPaginatable } from "../common/utils/pagination.js";
|
|
25
25
|
import { fetchAndDeserialize } from "../common/utils/fetch-and-deserialize.js";
|
|
26
26
|
import { deserializeFeatureFlag } from "../feature-flags/serializers/feature-flag.serializer.js";
|
|
27
|
+
import { toQueryString } from "../common/utils/query-string.js";
|
|
27
28
|
import { deserializeChallenge } from "../mfa/serializers/challenge.serializer.js";
|
|
28
29
|
import { sealData, unsealData } from "../common/crypto/seal.js";
|
|
29
30
|
import { getEnv } from "../common/utils/env.js";
|
|
@@ -50,6 +51,15 @@ var UserManagement = class {
|
|
|
50
51
|
const { clientId } = workos.options;
|
|
51
52
|
this.clientId = clientId;
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Resolve clientId from method options or fall back to constructor-provided value.
|
|
56
|
+
* @throws TypeError if clientId is not available from either source
|
|
57
|
+
*/
|
|
58
|
+
resolveClientId(clientId) {
|
|
59
|
+
const resolved = clientId ?? this.clientId;
|
|
60
|
+
if (!resolved) throw new TypeError("clientId is required. Provide it in method options or when initializing WorkOS.");
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
53
63
|
async getJWKS() {
|
|
54
64
|
const { createRemoteJWKSet } = await getJose();
|
|
55
65
|
if (!this.clientId) return;
|
|
@@ -83,9 +93,11 @@ var UserManagement = class {
|
|
|
83
93
|
return deserializeUser(data);
|
|
84
94
|
}
|
|
85
95
|
async authenticateWithMagicAuth(payload) {
|
|
86
|
-
const { session, ...remainingPayload } = payload;
|
|
96
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
97
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
87
98
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithMagicAuthOptions({
|
|
88
99
|
...remainingPayload,
|
|
100
|
+
clientId: resolvedClientId,
|
|
89
101
|
clientSecret: this.workos.key
|
|
90
102
|
}));
|
|
91
103
|
return this.prepareAuthenticationResponse({
|
|
@@ -94,9 +106,11 @@ var UserManagement = class {
|
|
|
94
106
|
});
|
|
95
107
|
}
|
|
96
108
|
async authenticateWithPassword(payload) {
|
|
97
|
-
const { session, ...remainingPayload } = payload;
|
|
109
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
110
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
98
111
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithPasswordOptions({
|
|
99
112
|
...remainingPayload,
|
|
113
|
+
clientId: resolvedClientId,
|
|
100
114
|
clientSecret: this.workos.key
|
|
101
115
|
}));
|
|
102
116
|
return this.prepareAuthenticationResponse({
|
|
@@ -104,40 +118,86 @@ var UserManagement = class {
|
|
|
104
118
|
session
|
|
105
119
|
});
|
|
106
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Exchange an authorization code for tokens.
|
|
123
|
+
*
|
|
124
|
+
* Auto-detects public vs confidential client mode:
|
|
125
|
+
* - If codeVerifier is provided: Uses PKCE flow (public client)
|
|
126
|
+
* - If no codeVerifier: Uses client_secret from API key (confidential client)
|
|
127
|
+
* - If both: Uses both client_secret AND codeVerifier (confidential client with PKCE)
|
|
128
|
+
*
|
|
129
|
+
* Using PKCE with confidential clients is recommended by OAuth 2.1 for defense
|
|
130
|
+
* in depth and provides additional CSRF protection on the authorization flow.
|
|
131
|
+
*
|
|
132
|
+
* @throws Error if neither codeVerifier nor API key is available
|
|
133
|
+
*/
|
|
107
134
|
async authenticateWithCode(payload) {
|
|
108
|
-
const { session, ...remainingPayload } = payload;
|
|
135
|
+
const { session, clientId, codeVerifier, ...remainingPayload } = payload;
|
|
136
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
137
|
+
if (codeVerifier !== void 0 && codeVerifier.trim() === "") throw new TypeError("codeVerifier cannot be an empty string. Generate a valid PKCE pair using workos.pkce.generate().");
|
|
138
|
+
const hasApiKey = !!this.workos.key;
|
|
139
|
+
if (!!!codeVerifier && !hasApiKey) throw new TypeError("authenticateWithCode requires either a codeVerifier (for public clients) or an API key configured on the WorkOS instance (for confidential clients).");
|
|
109
140
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithCodeOptions({
|
|
110
141
|
...remainingPayload,
|
|
111
|
-
|
|
112
|
-
|
|
142
|
+
clientId: resolvedClientId,
|
|
143
|
+
codeVerifier,
|
|
144
|
+
clientSecret: hasApiKey ? this.workos.key : void 0
|
|
145
|
+
}), { skipApiKeyCheck: !hasApiKey });
|
|
113
146
|
return this.prepareAuthenticationResponse({
|
|
114
147
|
authenticationResponse: deserializeAuthenticationResponse(data),
|
|
115
148
|
session
|
|
116
149
|
});
|
|
117
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Exchange an authorization code for tokens using PKCE (public client flow).
|
|
153
|
+
* Use this instead of authenticateWithCode() when the client cannot securely
|
|
154
|
+
* store a client_secret (browser, mobile, CLI, desktop apps).
|
|
155
|
+
*
|
|
156
|
+
* @param payload.clientId - Your WorkOS client ID
|
|
157
|
+
* @param payload.code - The authorization code from the OAuth callback
|
|
158
|
+
* @param payload.codeVerifier - The PKCE code verifier used to generate the code challenge
|
|
159
|
+
*/
|
|
118
160
|
async authenticateWithCodeAndVerifier(payload) {
|
|
119
|
-
const { session, ...remainingPayload } = payload;
|
|
120
|
-
const
|
|
161
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
162
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
163
|
+
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithCodeAndVerifierOptions({
|
|
164
|
+
...remainingPayload,
|
|
165
|
+
clientId: resolvedClientId
|
|
166
|
+
}), { skipApiKeyCheck: true });
|
|
121
167
|
return this.prepareAuthenticationResponse({
|
|
122
168
|
authenticationResponse: deserializeAuthenticationResponse(data),
|
|
123
169
|
session
|
|
124
170
|
});
|
|
125
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Refresh an access token using a refresh token.
|
|
174
|
+
* Automatically detects public client mode - if no API key is configured,
|
|
175
|
+
* omits client_secret from the request.
|
|
176
|
+
*/
|
|
126
177
|
async authenticateWithRefreshToken(payload) {
|
|
127
|
-
const { session, ...remainingPayload } = payload;
|
|
128
|
-
const
|
|
178
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
179
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
180
|
+
const isPublicClient = !this.workos.key;
|
|
181
|
+
const body = isPublicClient ? serializeAuthenticateWithRefreshTokenPublicClientOptions({
|
|
182
|
+
...remainingPayload,
|
|
183
|
+
clientId: resolvedClientId
|
|
184
|
+
}) : serializeAuthenticateWithRefreshTokenOptions({
|
|
129
185
|
...remainingPayload,
|
|
186
|
+
clientId: resolvedClientId,
|
|
130
187
|
clientSecret: this.workos.key
|
|
131
|
-
})
|
|
188
|
+
});
|
|
189
|
+
const { data } = await this.workos.post("/user_management/authenticate", body, { skipApiKeyCheck: isPublicClient });
|
|
132
190
|
return this.prepareAuthenticationResponse({
|
|
133
191
|
authenticationResponse: deserializeAuthenticationResponse(data),
|
|
134
192
|
session
|
|
135
193
|
});
|
|
136
194
|
}
|
|
137
195
|
async authenticateWithTotp(payload) {
|
|
138
|
-
const { session, ...remainingPayload } = payload;
|
|
196
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
197
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
139
198
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithTotpOptions({
|
|
140
199
|
...remainingPayload,
|
|
200
|
+
clientId: resolvedClientId,
|
|
141
201
|
clientSecret: this.workos.key
|
|
142
202
|
}));
|
|
143
203
|
return this.prepareAuthenticationResponse({
|
|
@@ -146,9 +206,11 @@ var UserManagement = class {
|
|
|
146
206
|
});
|
|
147
207
|
}
|
|
148
208
|
async authenticateWithEmailVerification(payload) {
|
|
149
|
-
const { session, ...remainingPayload } = payload;
|
|
209
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
210
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
150
211
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithEmailVerificationOptions({
|
|
151
212
|
...remainingPayload,
|
|
213
|
+
clientId: resolvedClientId,
|
|
152
214
|
clientSecret: this.workos.key
|
|
153
215
|
}));
|
|
154
216
|
return this.prepareAuthenticationResponse({
|
|
@@ -157,9 +219,11 @@ var UserManagement = class {
|
|
|
157
219
|
});
|
|
158
220
|
}
|
|
159
221
|
async authenticateWithOrganizationSelection(payload) {
|
|
160
|
-
const { session, ...remainingPayload } = payload;
|
|
222
|
+
const { session, clientId, ...remainingPayload } = payload;
|
|
223
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
161
224
|
const { data } = await this.workos.post("/user_management/authenticate", serializeAuthenticateWithOrganizationSelectionOptions({
|
|
162
225
|
...remainingPayload,
|
|
226
|
+
clientId: resolvedClientId,
|
|
163
227
|
clientSecret: this.workos.key
|
|
164
228
|
}));
|
|
165
229
|
return this.prepareAuthenticationResponse({
|
|
@@ -207,17 +271,21 @@ var UserManagement = class {
|
|
|
207
271
|
await jwtVerify(accessToken, jwks);
|
|
208
272
|
return true;
|
|
209
273
|
} catch (e) {
|
|
210
|
-
return false;
|
|
274
|
+
if (e instanceof Error && "code" in e && typeof e.code === "string" && (e.code.startsWith("ERR_JWT_") || e.code.startsWith("ERR_JWS_"))) return false;
|
|
275
|
+
throw e;
|
|
211
276
|
}
|
|
212
277
|
}
|
|
213
278
|
async prepareAuthenticationResponse({ authenticationResponse, session }) {
|
|
214
|
-
if (session?.sealSession)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
authenticationResponse,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
279
|
+
if (session?.sealSession) {
|
|
280
|
+
if (!this.workos.key) throw new Error("Session sealing requires server-side usage with an API key. Public clients should store tokens directly (e.g., secure storage on mobile, keychain on desktop).");
|
|
281
|
+
return {
|
|
282
|
+
...authenticationResponse,
|
|
283
|
+
sealedSession: await this.sealSessionDataFromAuthenticationResponse({
|
|
284
|
+
authenticationResponse,
|
|
285
|
+
cookiePassword: session.cookiePassword
|
|
286
|
+
})
|
|
287
|
+
};
|
|
288
|
+
}
|
|
221
289
|
return authenticationResponse;
|
|
222
290
|
}
|
|
223
291
|
async sealSessionDataFromAuthenticationResponse({ authenticationResponse, cookiePassword }) {
|
|
@@ -356,20 +424,107 @@ var UserManagement = class {
|
|
|
356
424
|
async revokeSession(payload) {
|
|
357
425
|
await this.workos.post("/user_management/sessions/revoke", serializeRevokeSessionOptions(payload));
|
|
358
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* Generate an OAuth 2.0 authorization URL.
|
|
429
|
+
*
|
|
430
|
+
* For public clients (browser, mobile, CLI), include PKCE parameters:
|
|
431
|
+
* - Generate PKCE using workos.pkce.generate()
|
|
432
|
+
* - Pass codeChallenge and codeChallengeMethod here
|
|
433
|
+
* - Store codeVerifier and pass to authenticateWithCode() later
|
|
434
|
+
*
|
|
435
|
+
* Or use getAuthorizationUrlWithPKCE() which handles PKCE automatically.
|
|
436
|
+
*/
|
|
359
437
|
getAuthorizationUrl(options) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
438
|
+
const { connectionId, codeChallenge, codeChallengeMethod, clientId, domainHint, loginHint, organizationId, provider, providerQueryParams, providerScopes, prompt, redirectUri, state, screenHint } = options;
|
|
439
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
440
|
+
if (!provider && !connectionId && !organizationId) throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
|
|
441
|
+
if (provider !== "authkit" && screenHint) throw new TypeError(`'screenHint' is only supported for 'authkit' provider`);
|
|
442
|
+
const query = toQueryString({
|
|
443
|
+
connection_id: connectionId,
|
|
444
|
+
code_challenge: codeChallenge,
|
|
445
|
+
code_challenge_method: codeChallengeMethod,
|
|
446
|
+
organization_id: organizationId,
|
|
447
|
+
domain_hint: domainHint,
|
|
448
|
+
login_hint: loginHint,
|
|
449
|
+
provider,
|
|
450
|
+
provider_query_params: providerQueryParams,
|
|
451
|
+
provider_scopes: providerScopes,
|
|
452
|
+
prompt,
|
|
453
|
+
client_id: resolvedClientId,
|
|
454
|
+
redirect_uri: redirectUri,
|
|
455
|
+
response_type: "code",
|
|
456
|
+
state,
|
|
457
|
+
screen_hint: screenHint
|
|
363
458
|
});
|
|
459
|
+
return `${this.workos.baseURL}/user_management/authorize?${query}`;
|
|
364
460
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
461
|
+
/**
|
|
462
|
+
* Generate an OAuth 2.0 authorization URL with automatic PKCE.
|
|
463
|
+
*
|
|
464
|
+
* This method generates PKCE parameters internally and returns them along with
|
|
465
|
+
* the authorization URL. Use this for public clients (CLI apps, Electron, mobile)
|
|
466
|
+
* that cannot securely store a client secret.
|
|
467
|
+
*
|
|
468
|
+
* @returns Object containing url, state, and codeVerifier
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* const { url, state, codeVerifier } = await workos.userManagement.getAuthorizationUrlWithPKCE({
|
|
473
|
+
* provider: 'authkit',
|
|
474
|
+
* clientId: 'client_123',
|
|
475
|
+
* redirectUri: 'myapp://callback',
|
|
476
|
+
* });
|
|
477
|
+
*
|
|
478
|
+
* // Store state and codeVerifier securely, then redirect user to url
|
|
479
|
+
* // After callback, exchange the code:
|
|
480
|
+
* const response = await workos.userManagement.authenticateWithCode({
|
|
481
|
+
* code: authorizationCode,
|
|
482
|
+
* codeVerifier,
|
|
483
|
+
* clientId: 'client_123',
|
|
484
|
+
* });
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
async getAuthorizationUrlWithPKCE(options) {
|
|
488
|
+
const { clientId, connectionId, domainHint, loginHint, organizationId, provider, providerQueryParams, providerScopes, prompt, redirectUri, screenHint } = options;
|
|
489
|
+
const resolvedClientId = this.resolveClientId(clientId);
|
|
490
|
+
if (!provider && !connectionId && !organizationId) throw new TypeError(`Incomplete arguments. Need to specify either a 'connectionId', 'organizationId', or 'provider'.`);
|
|
491
|
+
if (provider !== "authkit" && screenHint) throw new TypeError(`'screenHint' is only supported for 'authkit' provider`);
|
|
492
|
+
const pkce = await this.workos.pkce.generate();
|
|
493
|
+
const state = this.workos.pkce.generateCodeVerifier(43);
|
|
494
|
+
const query = toQueryString({
|
|
495
|
+
connection_id: connectionId,
|
|
496
|
+
code_challenge: pkce.codeChallenge,
|
|
497
|
+
code_challenge_method: "S256",
|
|
498
|
+
organization_id: organizationId,
|
|
499
|
+
domain_hint: domainHint,
|
|
500
|
+
login_hint: loginHint,
|
|
501
|
+
provider,
|
|
502
|
+
provider_query_params: providerQueryParams,
|
|
503
|
+
provider_scopes: providerScopes,
|
|
504
|
+
prompt,
|
|
505
|
+
client_id: resolvedClientId,
|
|
506
|
+
redirect_uri: redirectUri,
|
|
507
|
+
response_type: "code",
|
|
508
|
+
state,
|
|
509
|
+
screen_hint: screenHint
|
|
369
510
|
});
|
|
511
|
+
return {
|
|
512
|
+
url: `${this.workos.baseURL}/user_management/authorize?${query}`,
|
|
513
|
+
state,
|
|
514
|
+
codeVerifier: pkce.codeVerifier
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
getLogoutUrl(options) {
|
|
518
|
+
const { sessionId, returnTo } = options;
|
|
519
|
+
if (!sessionId) throw new TypeError(`Incomplete arguments. Need to specify 'sessionId'.`);
|
|
520
|
+
const url = new URL("/user_management/sessions/logout", this.workos.baseURL);
|
|
521
|
+
url.searchParams.set("session_id", sessionId);
|
|
522
|
+
if (returnTo) url.searchParams.set("return_to", returnTo);
|
|
523
|
+
return url.toString();
|
|
370
524
|
}
|
|
371
525
|
getJwksUrl(clientId) {
|
|
372
|
-
|
|
526
|
+
if (!clientId) throw new TypeError("clientId must be a valid clientId");
|
|
527
|
+
return `${this.workos.baseURL}/sso/jwks/${clientId}`;
|
|
373
528
|
}
|
|
374
529
|
};
|
|
375
530
|
|