@workos/authkit-session 0.3.4 → 0.5.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/README.md +111 -27
- package/dist/core/AuthKitCore.d.ts +20 -0
- package/dist/core/AuthKitCore.d.ts.map +1 -1
- package/dist/core/AuthKitCore.js +36 -4
- package/dist/core/AuthKitCore.js.map +1 -1
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts +2 -1
- package/dist/core/encryption/ironWebcryptoEncryption.d.ts.map +1 -1
- package/dist/core/encryption/ironWebcryptoEncryption.js +2 -2
- package/dist/core/encryption/ironWebcryptoEncryption.js.map +1 -1
- package/dist/core/errors.d.ts +9 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +18 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/pkce/cookieName.d.ts +17 -0
- package/dist/core/pkce/cookieName.d.ts.map +1 -0
- package/dist/core/pkce/cookieName.js +26 -0
- package/dist/core/pkce/cookieName.js.map +1 -0
- package/dist/core/pkce/cookieOptions.d.ts +34 -0
- package/dist/core/pkce/cookieOptions.d.ts.map +1 -0
- package/dist/core/pkce/cookieOptions.js +53 -0
- package/dist/core/pkce/cookieOptions.js.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts +46 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.js +85 -0
- package/dist/core/pkce/generateAuthorizationUrl.js.map +1 -0
- package/dist/core/pkce/state.d.ts +53 -0
- package/dist/core/pkce/state.d.ts.map +1 -0
- package/dist/core/pkce/state.js +91 -0
- package/dist/core/pkce/state.js.map +1 -0
- package/dist/core/session/CookieSessionStorage.d.ts +25 -15
- package/dist/core/session/CookieSessionStorage.d.ts.map +1 -1
- package/dist/core/session/CookieSessionStorage.js +20 -27
- package/dist/core/session/CookieSessionStorage.js.map +1 -1
- package/dist/core/session/TokenManager.js +2 -2
- package/dist/core/session/TokenManager.js.map +1 -1
- package/dist/core/session/serializeCookie.d.ts +13 -0
- package/dist/core/session/serializeCookie.d.ts.map +1 -0
- package/dist/core/session/serializeCookie.js +32 -0
- package/dist/core/session/serializeCookie.js.map +1 -0
- package/dist/core/session/types.d.ts +76 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/operations/AuthOperations.d.ts +15 -13
- package/dist/operations/AuthOperations.d.ts.map +1 -1
- package/dist/operations/AuthOperations.js +22 -34
- package/dist/operations/AuthOperations.js.map +1 -1
- package/dist/service/AuthService.d.ts +64 -15
- package/dist/service/AuthService.d.ts.map +1 -1
- package/dist/service/AuthService.js +171 -70
- package/dist/service/AuthService.js.map +1 -1
- package/dist/service/factory.d.ts.map +1 -1
- package/dist/service/factory.js +4 -3
- package/dist/service/factory.js.map +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +23 -0
- package/dist/utils.js.map +1 -1
- package/package.json +23 -20
- package/src/core/AuthKitCore.spec.ts +109 -0
- package/src/core/AuthKitCore.ts +55 -4
- package/src/core/encryption/ironWebcryptoEncryption.spec.ts +62 -0
- package/src/core/encryption/ironWebcryptoEncryption.ts +2 -2
- package/src/core/errors.spec.ts +33 -142
- package/src/core/errors.ts +21 -0
- package/src/core/pkce/cookieName.spec.ts +56 -0
- package/src/core/pkce/cookieName.ts +27 -0
- package/src/core/pkce/cookieOptions.spec.ts +144 -0
- package/src/core/pkce/cookieOptions.ts +61 -0
- package/src/core/pkce/generateAuthorizationUrl.ts +123 -0
- package/src/core/pkce/pkce.spec.ts +175 -0
- package/src/core/pkce/state.spec.ts +216 -0
- package/src/core/pkce/state.ts +120 -0
- package/src/core/session/CookieSessionStorage.spec.ts +79 -3
- package/src/core/session/CookieSessionStorage.ts +56 -36
- package/src/core/session/TokenManager.ts +2 -2
- package/src/core/session/serializeCookie.ts +33 -0
- package/src/core/session/types.ts +83 -2
- package/src/index.ts +11 -0
- package/src/operations/AuthOperations.spec.ts +107 -62
- package/src/operations/AuthOperations.ts +34 -40
- package/src/service/AuthService.spec.ts +750 -97
- package/src/service/AuthService.ts +210 -72
- package/src/service/factory.spec.ts +4 -3
- package/src/service/factory.ts +6 -3
- package/src/utils.ts +22 -0
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { WorkOS } from '@workos-inc/node';
|
|
2
2
|
import type { AuthKitCore } from '../core/AuthKitCore.js';
|
|
3
3
|
import type { AuthKitConfig } from '../core/config/types.js';
|
|
4
|
+
import {
|
|
5
|
+
type GeneratedAuthorizationUrl,
|
|
6
|
+
generateAuthorizationUrl,
|
|
7
|
+
} from '../core/pkce/generateAuthorizationUrl.js';
|
|
4
8
|
import type {
|
|
5
9
|
AuthResult,
|
|
6
10
|
GetAuthorizationUrlOptions,
|
|
7
11
|
Session,
|
|
12
|
+
SessionEncryption,
|
|
8
13
|
} from '../core/session/types.js';
|
|
9
14
|
|
|
10
15
|
/**
|
|
@@ -23,11 +28,18 @@ export class AuthOperations {
|
|
|
23
28
|
private core: AuthKitCore;
|
|
24
29
|
private client: WorkOS;
|
|
25
30
|
private config: AuthKitConfig;
|
|
31
|
+
private encryption: SessionEncryption;
|
|
26
32
|
|
|
27
|
-
constructor(
|
|
33
|
+
constructor(
|
|
34
|
+
core: AuthKitCore,
|
|
35
|
+
client: WorkOS,
|
|
36
|
+
config: AuthKitConfig,
|
|
37
|
+
encryption: SessionEncryption,
|
|
38
|
+
) {
|
|
28
39
|
this.core = core;
|
|
29
40
|
this.client = client;
|
|
30
41
|
this.config = config;
|
|
42
|
+
this.encryption = encryption;
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
/**
|
|
@@ -115,63 +127,45 @@ export class AuthOperations {
|
|
|
115
127
|
}
|
|
116
128
|
|
|
117
129
|
/**
|
|
118
|
-
*
|
|
130
|
+
* Create a PKCE-bound WorkOS authorization URL.
|
|
119
131
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
132
|
+
* Returns the URL, the sealed state blob (to be used as both the cookie
|
|
133
|
+
* value and — already present in the URL — the OAuth `state` param), and
|
|
134
|
+
* the cookie options the verifier cookie should be written with.
|
|
135
|
+
* AuthService dispatches the write via `SessionStorage.setCookie`.
|
|
123
136
|
*
|
|
124
|
-
* @param options -
|
|
125
|
-
* @returns The authorization URL
|
|
137
|
+
* @param options - returnPathname, screenHint, custom state, redirectUri, etc.
|
|
126
138
|
*/
|
|
127
|
-
async
|
|
139
|
+
async createAuthorization(
|
|
128
140
|
options: GetAuthorizationUrlOptions = {},
|
|
129
|
-
): Promise<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
: null;
|
|
136
|
-
|
|
137
|
-
// If both internal and custom state, combine as internal.custom
|
|
138
|
-
// Otherwise use whichever is provided
|
|
139
|
-
const state =
|
|
140
|
-
internalState && options.state
|
|
141
|
-
? `${internalState}.${options.state}`
|
|
142
|
-
: internalState || options.state || undefined;
|
|
143
|
-
|
|
144
|
-
return this.client.userManagement.getAuthorizationUrl({
|
|
145
|
-
provider: 'authkit',
|
|
146
|
-
redirectUri: options.redirectUri ?? this.config.redirectUri,
|
|
147
|
-
screenHint: options.screenHint,
|
|
148
|
-
organizationId: options.organizationId,
|
|
149
|
-
loginHint: options.loginHint,
|
|
150
|
-
prompt: options.prompt,
|
|
151
|
-
clientId: this.config.clientId,
|
|
152
|
-
state,
|
|
141
|
+
): Promise<GeneratedAuthorizationUrl> {
|
|
142
|
+
return generateAuthorizationUrl({
|
|
143
|
+
client: this.client,
|
|
144
|
+
config: this.config,
|
|
145
|
+
encryption: this.encryption,
|
|
146
|
+
options,
|
|
153
147
|
});
|
|
154
148
|
}
|
|
155
149
|
|
|
156
150
|
/**
|
|
157
|
-
* Convenience method:
|
|
151
|
+
* Convenience method: Create sign-in authorization URL.
|
|
158
152
|
*/
|
|
159
|
-
async
|
|
153
|
+
async createSignIn(
|
|
160
154
|
options: Omit<GetAuthorizationUrlOptions, 'screenHint'> = {},
|
|
161
|
-
): Promise<
|
|
162
|
-
return this.
|
|
155
|
+
): Promise<GeneratedAuthorizationUrl> {
|
|
156
|
+
return this.createAuthorization({
|
|
163
157
|
...options,
|
|
164
158
|
screenHint: 'sign-in',
|
|
165
159
|
});
|
|
166
160
|
}
|
|
167
161
|
|
|
168
162
|
/**
|
|
169
|
-
* Convenience method:
|
|
163
|
+
* Convenience method: Create sign-up authorization URL.
|
|
170
164
|
*/
|
|
171
|
-
async
|
|
165
|
+
async createSignUp(
|
|
172
166
|
options: Omit<GetAuthorizationUrlOptions, 'screenHint'> = {},
|
|
173
|
-
): Promise<
|
|
174
|
-
return this.
|
|
167
|
+
): Promise<GeneratedAuthorizationUrl> {
|
|
168
|
+
return this.createAuthorization({
|
|
175
169
|
...options,
|
|
176
170
|
screenHint: 'sign-up',
|
|
177
171
|
});
|