@workos/authkit-session 0.3.2 → 0.4.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 +94 -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/client/types.d.ts.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/cookieOptions.d.ts +36 -0
- package/dist/core/pkce/cookieOptions.d.ts.map +1 -0
- package/dist/core/pkce/cookieOptions.js +55 -0
- package/dist/core/pkce/cookieOptions.js.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts +45 -0
- package/dist/core/pkce/generateAuthorizationUrl.d.ts.map +1 -0
- package/dist/core/pkce/generateAuthorizationUrl.js +82 -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 +71 -2
- package/dist/core/session/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 +58 -15
- package/dist/service/AuthService.d.ts.map +1 -1
- package/dist/service/AuthService.js +157 -71
- 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 +35 -29
- package/src/core/AuthKitCore.spec.ts +109 -0
- package/src/core/AuthKitCore.ts +55 -4
- package/src/core/client/types.ts +3 -6
- 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/cookieOptions.spec.ts +144 -0
- package/src/core/pkce/cookieOptions.ts +64 -0
- package/src/core/pkce/generateAuthorizationUrl.ts +123 -0
- package/src/core/pkce/pkce.spec.ts +166 -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 +60 -39
- package/src/core/session/TokenManager.ts +2 -2
- package/src/core/session/serializeCookie.ts +33 -0
- package/src/core/session/types.ts +79 -2
- package/src/index.ts +3 -0
- package/src/operations/AuthOperations.spec.ts +107 -62
- package/src/operations/AuthOperations.ts +34 -40
- package/src/service/AuthService.spec.ts +615 -98
- package/src/service/AuthService.ts +198 -73
- package/src/service/factory.spec.ts +4 -3
- package/src/service/factory.ts +6 -3
- package/src/utils.ts +22 -0
package/README.md
CHANGED
|
@@ -49,25 +49,26 @@ configure({
|
|
|
49
49
|
### 2. Create Storage Adapter
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
import {
|
|
53
|
-
CookieSessionStorage,
|
|
54
|
-
parseCookieHeader,
|
|
55
|
-
} from '@workos/authkit-session';
|
|
52
|
+
import { CookieSessionStorage } from '@workos/authkit-session';
|
|
56
53
|
|
|
57
54
|
export class MyFrameworkStorage extends CookieSessionStorage<
|
|
58
55
|
Request,
|
|
59
56
|
Response
|
|
60
57
|
> {
|
|
61
|
-
async
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
64
|
-
|
|
58
|
+
async getCookie(request: Request, name: string): Promise<string | null> {
|
|
59
|
+
const header = request.headers.get('cookie');
|
|
60
|
+
if (!header) return null;
|
|
61
|
+
for (const part of header.split(';')) {
|
|
62
|
+
const [k, ...rest] = part.trim().split('=');
|
|
63
|
+
if (k === name) return decodeURIComponent(rest.join('='));
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
// Optional: override if your framework can mutate responses
|
|
68
69
|
protected async applyHeaders(
|
|
69
70
|
response: Response | undefined,
|
|
70
|
-
headers: Record<string, string>,
|
|
71
|
+
headers: Record<string, string | string[]>,
|
|
71
72
|
): Promise<{ response: Response }> {
|
|
72
73
|
const newResponse = response
|
|
73
74
|
? new Response(response.body, {
|
|
@@ -77,16 +78,20 @@ export class MyFrameworkStorage extends CookieSessionStorage<
|
|
|
77
78
|
})
|
|
78
79
|
: new Response();
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
for (const v of value) newResponse.headers.append(key, v);
|
|
84
|
+
} else {
|
|
85
|
+
newResponse.headers.append(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
83
88
|
|
|
84
89
|
return { response: newResponse };
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
```
|
|
88
93
|
|
|
89
|
-
`CookieSessionStorage` provides `this.cookieName`, `this.cookieOptions`,
|
|
94
|
+
`CookieSessionStorage` provides `this.cookieName`, `this.cookieOptions`, and generic `setCookie`/`clearCookie`/`serializeCookie` primitives. `getSession`/`saveSession`/`clearSession` are one-line wrappers — you only implement `getCookie`.
|
|
90
95
|
|
|
91
96
|
### 3. Create Service
|
|
92
97
|
|
|
@@ -117,13 +122,18 @@ export const authMiddleware = () => {
|
|
|
117
122
|
undefined,
|
|
118
123
|
refreshedSessionData,
|
|
119
124
|
);
|
|
120
|
-
|
|
125
|
+
const setCookie = headers?.['Set-Cookie'];
|
|
126
|
+
if (setCookie) {
|
|
121
127
|
const newResponse = new Response(result.response.body, {
|
|
122
128
|
status: result.response.status,
|
|
123
129
|
statusText: result.response.statusText,
|
|
124
130
|
headers: result.response.headers,
|
|
125
131
|
});
|
|
126
|
-
|
|
132
|
+
// Append each entry — never `.set()` with an array (comma-joined
|
|
133
|
+
// Set-Cookie is not a valid single HTTP header).
|
|
134
|
+
for (const v of Array.isArray(setCookie) ? setCookie : [setCookie]) {
|
|
135
|
+
newResponse.headers.append('Set-Cookie', v);
|
|
136
|
+
}
|
|
127
137
|
return { ...result, response: newResponse };
|
|
128
138
|
}
|
|
129
139
|
}
|
|
@@ -160,7 +170,7 @@ auth.claims.sid; // string
|
|
|
160
170
|
| `WORKOS_API_KEY` | `apiKey` | WorkOS API key |
|
|
161
171
|
| `WORKOS_REDIRECT_URI` | `redirectUri` | OAuth callback URL |
|
|
162
172
|
| `WORKOS_COOKIE_PASSWORD` | `cookiePassword` | 32+ char encryption key |
|
|
163
|
-
| `WORKOS_COOKIE_NAME` | `cookieName` | Cookie name (default: `
|
|
173
|
+
| `WORKOS_COOKIE_NAME` | `cookieName` | Cookie name (default: `wos-session`) |
|
|
164
174
|
| `WORKOS_COOKIE_MAX_AGE` | `cookieMaxAge` | Cookie lifetime in seconds |
|
|
165
175
|
| `WORKOS_COOKIE_DOMAIN` | `cookieDomain` | Cookie domain |
|
|
166
176
|
| `WORKOS_COOKIE_SAME_SITE` | `cookieSameSite` | `lax`, `strict`, or `none` |
|
|
@@ -180,16 +190,72 @@ authService.saveSession(response, sessionData) // → { response?, headers? }
|
|
|
180
190
|
authService.clearSession(response)
|
|
181
191
|
|
|
182
192
|
// WorkOS Operations
|
|
183
|
-
authService.signOut(sessionId, { returnTo }) // → { logoutUrl,
|
|
193
|
+
authService.signOut(sessionId, { returnTo }) // → { logoutUrl, response?, headers? }
|
|
184
194
|
authService.refreshSession(session, organizationId?)
|
|
185
195
|
authService.switchOrganization(session, organizationId)
|
|
186
196
|
|
|
187
|
-
// URL Generation
|
|
188
|
-
authService.
|
|
189
|
-
authService.
|
|
190
|
-
authService.
|
|
197
|
+
// URL Generation — write verifier cookie, return { url, response?, headers? }
|
|
198
|
+
authService.createAuthorization(response, options)
|
|
199
|
+
authService.createSignIn(response, options)
|
|
200
|
+
authService.createSignUp(response, options)
|
|
201
|
+
|
|
202
|
+
// Error-path cleanup for the PKCE verifier cookie
|
|
203
|
+
// (response may be `undefined` for headers-only adapters)
|
|
204
|
+
authService.clearPendingVerifier(response, { redirectUri? })
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### PKCE verifier cookie (`wos-auth-verifier`)
|
|
208
|
+
|
|
209
|
+
This library binds every OAuth sign-in to a PKCE code verifier, so a leaked
|
|
210
|
+
`state` value on its own cannot be used to complete a session hijack.
|
|
211
|
+
|
|
212
|
+
The verifier is sealed into a single blob that serves two roles:
|
|
213
|
+
|
|
214
|
+
1. It is sent to WorkOS as the OAuth `state` query parameter.
|
|
215
|
+
2. It is set as a short-lived HTTP-only cookie (`wos-auth-verifier`, 10 min).
|
|
216
|
+
|
|
217
|
+
The cookie is written and read through `SessionStorage`. Callers don't see
|
|
218
|
+
sealed blobs or cookie options:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
// Sign in: library writes the verifier cookie via storage, returns the URL + headers
|
|
222
|
+
const { url, headers } = await authService.createSignIn(response, {
|
|
223
|
+
returnPathname: '/dashboard',
|
|
224
|
+
});
|
|
225
|
+
return new Response(null, {
|
|
226
|
+
status: 302,
|
|
227
|
+
headers: { ...headers, Location: url },
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// Callback: library reads the verifier via storage, byte-compares, then exchanges
|
|
231
|
+
await authService.handleCallback(request, response, {
|
|
232
|
+
code,
|
|
233
|
+
state, // from URL
|
|
234
|
+
});
|
|
191
235
|
```
|
|
192
236
|
|
|
237
|
+
On success, `handleCallback` returns a `Set-Cookie` entry in `headers` as a
|
|
238
|
+
`string[]` with two values — the session cookie AND a clear for the verifier
|
|
239
|
+
cookie. Adapters must append each entry as its own `Set-Cookie` HTTP header
|
|
240
|
+
(never comma-join). The bag key is case-insensitive — `mergeHeaderBags`
|
|
241
|
+
preserves the adapter's casing — so look it up that way:
|
|
242
|
+
|
|
243
|
+
```ts
|
|
244
|
+
const setCookie =
|
|
245
|
+
result.headers?.['Set-Cookie'] ?? result.headers?.['set-cookie'];
|
|
246
|
+
if (setCookie) {
|
|
247
|
+
for (const v of Array.isArray(setCookie) ? setCookie : [setCookie]) {
|
|
248
|
+
response.headers.append('Set-Cookie', v);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Mismatched state and cookie raise `OAuthStateMismatchError`. A missing cookie
|
|
254
|
+
(typical cause: Set-Cookie stripped by a proxy) raises
|
|
255
|
+
`PKCECookieMissingError`. On either error path — or any early bail-out before
|
|
256
|
+
`handleCallback` runs — call `authService.clearPendingVerifier(response)` to
|
|
257
|
+
emit a delete header.
|
|
258
|
+
|
|
193
259
|
### Direct Access (Advanced)
|
|
194
260
|
|
|
195
261
|
For maximum control, use the primitives directly:
|
|
@@ -198,14 +264,15 @@ For maximum control, use the primitives directly:
|
|
|
198
264
|
import {
|
|
199
265
|
AuthKitCore,
|
|
200
266
|
AuthOperations,
|
|
201
|
-
getWorkOS,
|
|
202
267
|
getConfigurationProvider,
|
|
268
|
+
getWorkOS,
|
|
269
|
+
sessionEncryption,
|
|
203
270
|
} from '@workos/authkit-session';
|
|
204
271
|
|
|
205
|
-
const config = getConfigurationProvider();
|
|
206
|
-
const client = getWorkOS(
|
|
207
|
-
const core = new AuthKitCore(config, client,
|
|
208
|
-
const operations = new AuthOperations(core, client, config);
|
|
272
|
+
const config = getConfigurationProvider().getConfig();
|
|
273
|
+
const client = getWorkOS();
|
|
274
|
+
const core = new AuthKitCore(config, client, sessionEncryption);
|
|
275
|
+
const operations = new AuthOperations(core, client, config, sessionEncryption);
|
|
209
276
|
|
|
210
277
|
// Use core.validateAndRefresh(), core.encryptSession(), etc.
|
|
211
278
|
```
|
|
@@ -213,7 +280,7 @@ const operations = new AuthOperations(core, client, config);
|
|
|
213
280
|
## Technical Details
|
|
214
281
|
|
|
215
282
|
- **JWKS Caching**: Keys fetched on-demand, cached for process lifetime. `jose` handles key rotation automatically.
|
|
216
|
-
- **Token
|
|
283
|
+
- **Token Refresh**: `validateAndRefresh` refreshes when `verifyToken` fails (i.e. when the access token is expired or invalid). `isTokenExpiring(token, buffer)` is available as a separate helper for callers that want to proactively refresh before expiry.
|
|
217
284
|
- **Session Encryption**: AES-256-CBC + SHA-256 HMAC via `iron-webcrypto`.
|
|
218
285
|
- **Lazy Initialization**: `createAuthService()` defers initialization until first use, allowing `configure()` to be called later.
|
|
219
286
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Impersonator, User, WorkOS } from '@workos-inc/node';
|
|
2
2
|
import type { AuthKitConfig } from './config/types.js';
|
|
3
|
+
import { type PKCEState } from './pkce/state.js';
|
|
3
4
|
import type { BaseTokenClaims, CustomClaims, Session, SessionEncryption } from './session/types.js';
|
|
4
5
|
/**
|
|
5
6
|
* AuthKitCore provides pure business logic for authentication operations.
|
|
@@ -70,6 +71,25 @@ export declare class AuthKitCore {
|
|
|
70
71
|
* @throws SessionEncryptionError if decryption fails
|
|
71
72
|
*/
|
|
72
73
|
decryptSession(encryptedSession: string): Promise<Session>;
|
|
74
|
+
/**
|
|
75
|
+
* Verify the OAuth callback state against the PKCE verifier cookie and
|
|
76
|
+
* return the unsealed state blob.
|
|
77
|
+
*
|
|
78
|
+
* Core owns encryption, so verification lives here rather than on
|
|
79
|
+
* AuthService. Byte-compares the query-string `state` against the cookie
|
|
80
|
+
* value BEFORE attempting to decrypt — smaller crypto attack surface and
|
|
81
|
+
* no decryption cost on obvious mismatches.
|
|
82
|
+
*
|
|
83
|
+
* @throws {OAuthStateMismatchError} state missing or does not match cookie
|
|
84
|
+
* @throws {PKCECookieMissingError} cookie not sent — typically a proxy or
|
|
85
|
+
* Set-Cookie propagation issue on the adapter's callback path
|
|
86
|
+
* @throws {SessionEncryptionError} seal tampered, wrong password, TTL expired,
|
|
87
|
+
* or schema mismatch on the unsealed payload
|
|
88
|
+
*/
|
|
89
|
+
verifyCallbackState(params: {
|
|
90
|
+
stateFromUrl: string | undefined;
|
|
91
|
+
cookieValue: string | undefined;
|
|
92
|
+
}): Promise<PKCEState>;
|
|
73
93
|
/**
|
|
74
94
|
* Refresh tokens using WorkOS API.
|
|
75
95
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthKitCore.d.ts","sourceRoot":"","sources":["../../src/core/AuthKitCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthKitCore.d.ts","sourceRoot":"","sources":["../../src/core/AuthKitCore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE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AS,CAAC;IA2BtB;;;;;;;;OAQG;IACG,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,EACvB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAChD,OAAO,CAAC;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,IAAI,CAAC;QACX,YAAY,EAAE,YAAY,GAAG,SAAS,CAAC;KACxC,CAAC;IAoBF;;;;;;;;;;;OAWG;IACG,kBAAkB,CAAC,aAAa,GAAG,YAAY,EACnD,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,GACrD,OAAO,CAAC;QACT,KAAK,EAAE,OAAO,CAAC;QACf,SAAS,EAAE,OAAO,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,eAAe,GAAG,aAAa,CAAC;KACzC,CAAC;CA8CH"}
|
package/dist/core/AuthKitCore.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRemoteJWKSet, decodeJwt, jwtVerify } from 'jose';
|
|
2
|
-
import { once } from '../utils.js';
|
|
3
|
-
import { SessionEncryptionError, TokenRefreshError } from './errors.js';
|
|
2
|
+
import { constantTimeEqual, once } from '../utils.js';
|
|
3
|
+
import { OAuthStateMismatchError, PKCECookieMissingError, SessionEncryptionError, TokenRefreshError, } from './errors.js';
|
|
4
|
+
import { unsealState } from './pkce/state.js';
|
|
4
5
|
/**
|
|
5
6
|
* AuthKitCore provides pure business logic for authentication operations.
|
|
6
7
|
*
|
|
@@ -80,8 +81,8 @@ export class AuthKitCore {
|
|
|
80
81
|
try {
|
|
81
82
|
return decodeJwt(token);
|
|
82
83
|
}
|
|
83
|
-
catch (
|
|
84
|
-
throw new Error('Invalid token');
|
|
84
|
+
catch (cause) {
|
|
85
|
+
throw new Error('Invalid token', { cause });
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
/**
|
|
@@ -119,6 +120,37 @@ export class AuthKitCore {
|
|
|
119
120
|
throw new SessionEncryptionError('Failed to decrypt session', error);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Verify the OAuth callback state against the PKCE verifier cookie and
|
|
125
|
+
* return the unsealed state blob.
|
|
126
|
+
*
|
|
127
|
+
* Core owns encryption, so verification lives here rather than on
|
|
128
|
+
* AuthService. Byte-compares the query-string `state` against the cookie
|
|
129
|
+
* value BEFORE attempting to decrypt — smaller crypto attack surface and
|
|
130
|
+
* no decryption cost on obvious mismatches.
|
|
131
|
+
*
|
|
132
|
+
* @throws {OAuthStateMismatchError} state missing or does not match cookie
|
|
133
|
+
* @throws {PKCECookieMissingError} cookie not sent — typically a proxy or
|
|
134
|
+
* Set-Cookie propagation issue on the adapter's callback path
|
|
135
|
+
* @throws {SessionEncryptionError} seal tampered, wrong password, TTL expired,
|
|
136
|
+
* or schema mismatch on the unsealed payload
|
|
137
|
+
*/
|
|
138
|
+
async verifyCallbackState(params) {
|
|
139
|
+
const { stateFromUrl, cookieValue } = params;
|
|
140
|
+
if (!stateFromUrl) {
|
|
141
|
+
throw new OAuthStateMismatchError('Missing state parameter from callback URL');
|
|
142
|
+
}
|
|
143
|
+
if (!cookieValue) {
|
|
144
|
+
throw new PKCECookieMissingError('PKCE verifier cookie missing — cannot verify OAuth state. Ensure Set-Cookie headers are propagated on redirects.');
|
|
145
|
+
}
|
|
146
|
+
const encoder = new TextEncoder();
|
|
147
|
+
const urlBytes = encoder.encode(stateFromUrl);
|
|
148
|
+
const cookieBytes = encoder.encode(cookieValue);
|
|
149
|
+
if (!constantTimeEqual(urlBytes, cookieBytes)) {
|
|
150
|
+
throw new OAuthStateMismatchError('OAuth state mismatch');
|
|
151
|
+
}
|
|
152
|
+
return unsealState(this.encryption, this.config.cookiePassword, cookieValue);
|
|
153
|
+
}
|
|
122
154
|
/**
|
|
123
155
|
* Refresh tokens using WorkOS API.
|
|
124
156
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthKitCore.js","sourceRoot":"","sources":["../../src/core/AuthKitCore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthKitCore.js","sourceRoot":"","sources":["../../src/core/AuthKitCore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9D;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAgB;IACtB,MAAM,CAAS;IACf,UAAU,CAAoB;IAC9B,QAAQ,CAAS;IAEzB,YACE,MAAqB,EACrB,MAAc,EACd,UAA6B;QAE7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;IAClC,CAAC;IAED;;OAEG;IACc,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,CACxC,kBAAkB,CAChB,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,IA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AM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;CACpC"}
|
|
@@ -10,8 +10,9 @@ export declare class SessionEncryption implements SessionEncryptionInterface {
|
|
|
10
10
|
password: string;
|
|
11
11
|
ttl?: number | undefined;
|
|
12
12
|
}): Promise<string>;
|
|
13
|
-
unsealData<T = unknown>(encryptedData: string, { password }: {
|
|
13
|
+
unsealData<T = unknown>(encryptedData: string, { password, ttl }: {
|
|
14
14
|
password: string;
|
|
15
|
+
ttl?: number | undefined;
|
|
15
16
|
}): Promise<T>;
|
|
16
17
|
}
|
|
17
18
|
declare const ironWebcryptoEncryption: SessionEncryption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ironWebcryptoEncryption.d.ts","sourceRoot":"","sources":["../../../src/core/encryption/ironWebcryptoEncryption.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAE3F;;GAEG;AACH,qBAAa,iBAAkB,YAAW,0BAA0B;IAClE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAO;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAGzC,OAAO,CAAC,SAAS;IAaX,QAAQ,CACZ,IAAI,EAAE,OAAO,EACb,EAAE,QAAQ,EAAE,GAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;IAgCjE,UAAU,CAAC,CAAC,GAAG,OAAO,EAC1B,aAAa,EAAE,MAAM,EACrB,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,
|
|
1
|
+
{"version":3,"file":"ironWebcryptoEncryption.d.ts","sourceRoot":"","sources":["../../../src/core/encryption/ironWebcryptoEncryption.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAE3F;;GAEG;AACH,qBAAa,iBAAkB,YAAW,0BAA0B;IAClE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAO;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAGzC,OAAO,CAAC,SAAS;IAaX,QAAQ,CACZ,IAAI,EAAE,OAAO,EACb,EAAE,QAAQ,EAAE,GAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;IAgCjE,UAAU,CAAC,CAAC,GAAG,OAAO,EAC1B,aAAa,EAAE,MAAM,EACrB,EAAE,QAAQ,EAAE,GAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GACpE,OAAO,CAAC,CAAC,CAAC;CAoCd;AAED,QAAA,MAAM,uBAAuB,mBAA0B,CAAC;AAExD,eAAe,uBAAuB,CAAC"}
|
|
@@ -40,7 +40,7 @@ export class SessionEncryption {
|
|
|
40
40
|
return `${seal}${this.versionDelimiter}${this.currentMajorVersion}`;
|
|
41
41
|
}
|
|
42
42
|
// Decrypt data from iron-session with HMAC verification
|
|
43
|
-
async unsealData(encryptedData, { password }) {
|
|
43
|
+
async unsealData(encryptedData, { password, ttl = 0 }) {
|
|
44
44
|
// First, parse the seal to extract the version
|
|
45
45
|
const { sealWithoutVersion, tokenVersion } = this.parseSeal(encryptedData);
|
|
46
46
|
// Format password as a map like iron-session expects
|
|
@@ -59,7 +59,7 @@ export class SessionEncryption {
|
|
|
59
59
|
iterations: 1,
|
|
60
60
|
minPasswordlength: 32,
|
|
61
61
|
},
|
|
62
|
-
ttl: 0
|
|
62
|
+
ttl: ttl * 1000, // Convert seconds to milliseconds. 0 = no TTL enforcement.
|
|
63
63
|
timestampSkewSec: 60,
|
|
64
64
|
localtimeOffsetMsec: 0,
|
|
65
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ironWebcryptoEncryption.js","sourceRoot":"","sources":["../../../src/core/encryption/ironWebcryptoEncryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGxE;;GAEG;AACH,MAAM,OAAO,iBAAiB;IACX,gBAAgB,GAAG,GAAG,CAAC;IACvB,mBAAmB,GAAG,CAAC,CAAC;IAEzC,oDAAoD;IAC5C,SAAS,CAAC,IAAY;QAI5B,MAAM,CAAC,kBAAkB,GAAG,EAAE,EAAE,oBAAoB,CAAC,GAAG,IAAI,CAAC,KAAK,CAChE,IAAI,CAAC,gBAAgB,CACtB,CAAC;QACF,MAAM,YAAY,GAChB,oBAAoB,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;QAC3E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,CAAC;IAC9C,CAAC;IAED,4DAA4D;IAC5D,KAAK,CAAC,QAAQ,CACZ,IAAa,EACb,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,EAAkD;QAErE,0CAA0C;QAC1C,MAAM,WAAW,GAAG;YAClB,EAAE,EAAE,GAAG;YACP,MAAM,EAAE,QAAQ;SACjB,CAAC;QAEF,sEAAsE;QACtE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,WAAW,EAAE;YAC7C,UAAU,EAAE;gBACV,QAAQ,EAAE,GAAG;gBACb,SAAS,EAAE,aAAa;gBACxB,UAAU,EAAE,CAAC;gBACb,iBAAiB,EAAE,EAAE;aACtB;YACD,SAAS,EAAE;gBACT,QAAQ,EAAE,GAAG;gBACb,SAAS,EAAE,QAAQ;gBACn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gBAAgB,EAAE,EAAE;YACpB,mBAAmB,EAAE,CAAC;SACvB,CAAC,CAAC;QAEH,oCAAoC;QACpC,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,IAAS,CAAC;QACnB,CAAC;aAAM,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;YACjC,4DAA4D;YAC5D,OAAO,EAAE,GAAI,IAAY,CAAC,UAAU,EAAO,CAAC;QAC9C,CAAC;QAED,OAAO,IAAS,CAAC;IACnB,CAAC;CACF;AAED,MAAM,uBAAuB,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAExD,eAAe,uBAAuB,CAAC"}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ export declare class SessionEncryptionError extends AuthKitError {
|
|
|
8
8
|
export declare class TokenValidationError extends AuthKitError {
|
|
9
9
|
constructor(message: string, cause?: unknown);
|
|
10
10
|
}
|
|
11
|
+
export declare class OAuthStateMismatchError extends AuthKitError {
|
|
12
|
+
constructor(message: string, cause?: unknown);
|
|
13
|
+
}
|
|
14
|
+
export declare class PKCECookieMissingError extends AuthKitError {
|
|
15
|
+
constructor(message: string, cause?: unknown);
|
|
16
|
+
}
|
|
17
|
+
export declare class PKCEPayloadTooLargeError extends AuthKitError {
|
|
18
|
+
constructor(message: string, cause?: unknown);
|
|
19
|
+
}
|
|
11
20
|
export declare class TokenRefreshError extends AuthKitError {
|
|
12
21
|
readonly userId?: string;
|
|
13
22
|
readonly sessionId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG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C5C,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAI7C;AAED,qBAAa,iBAAkB,SAAQ,YAAY;IACjD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,EACf,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;CAOpD"}
|
package/dist/core/errors.js
CHANGED
|
@@ -19,6 +19,24 @@ export class TokenValidationError extends AuthKitError {
|
|
|
19
19
|
this.name = 'TokenValidationError';
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
export class OAuthStateMismatchError extends AuthKitError {
|
|
23
|
+
constructor(message, cause) {
|
|
24
|
+
super(message, cause);
|
|
25
|
+
this.name = 'OAuthStateMismatchError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class PKCECookieMissingError extends AuthKitError {
|
|
29
|
+
constructor(message, cause) {
|
|
30
|
+
super(message, cause);
|
|
31
|
+
this.name = 'PKCECookieMissingError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class PKCEPayloadTooLargeError extends AuthKitError {
|
|
35
|
+
constructor(message, cause) {
|
|
36
|
+
super(message, cause);
|
|
37
|
+
this.name = 'PKCEPayloadTooLargeError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
22
40
|
export class TokenRefreshError extends AuthKitError {
|
|
23
41
|
userId;
|
|
24
42
|
sessionId;
|
package/dist/core/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,IAAI,CAAuB;IAE3B,YAAY,OAAe,EAAE,KAAe,EAAE,I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CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AuthKitConfig } from '../config/types.js';
|
|
2
|
+
import type { CookieOptions } from '../session/types.js';
|
|
3
|
+
/** Name of the PKCE verifier cookie on the wire. */
|
|
4
|
+
export declare const PKCE_COOKIE_NAME = "wos-auth-verifier";
|
|
5
|
+
/**
|
|
6
|
+
* PKCE verifier cookie lifetime (seconds). Matches the 10-minute convention
|
|
7
|
+
* used by Arctic, openid-client, Clerk, and Okta for short-lived OAuth state
|
|
8
|
+
* cookies — long enough to accommodate slow sign-ins (out-of-band 2FA, tab
|
|
9
|
+
* switching) and short enough to keep the replay window tight if the sealed
|
|
10
|
+
* blob leaks.
|
|
11
|
+
*
|
|
12
|
+
* The same value is used as both the `Max-Age` cookie attribute and the
|
|
13
|
+
* sealed payload's TTL, so both layers reject a stale blob.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PKCE_COOKIE_MAX_AGE = 600;
|
|
16
|
+
/**
|
|
17
|
+
* Compute PKCE verifier cookie options from config + the resolved redirect URI.
|
|
18
|
+
*
|
|
19
|
+
* Behavior:
|
|
20
|
+
* - `sameSite: 'strict'` is downgraded to `'lax'` so the cookie survives the
|
|
21
|
+
* cross-site redirect back from WorkOS.
|
|
22
|
+
* - `sameSite: 'none'` is preserved (iframe/embed flows require it).
|
|
23
|
+
* - `secure` is forced to `true` when `sameSite === 'none'` (required by
|
|
24
|
+
* modern browsers). Otherwise it is inferred from the redirect URI's
|
|
25
|
+
* protocol, defaulting fail-closed to `true` on invalid/missing URLs.
|
|
26
|
+
* - `path` is always `/`. The cookie gets sent on every same-origin request
|
|
27
|
+
* during the 10-minute window, which is fine — it's HttpOnly and expires
|
|
28
|
+
* quickly. The tradeoff favors DX: path-scoped cookies are invisible in
|
|
29
|
+
* Chrome DevTools' Application panel from any page outside the scoped
|
|
30
|
+
* path, which makes PKCE wiring look broken even when it works.
|
|
31
|
+
*
|
|
32
|
+
* Internal helper — not exported from the package. Callers get cookie options
|
|
33
|
+
* indirectly via `AuthService.createSignIn` / `clearPendingVerifier`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getPKCECookieOptions(config: AuthKitConfig, redirectUri?: string): CookieOptions;
|
|
36
|
+
//# sourceMappingURL=cookieOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieOptions.d.ts","sourceRoot":"","sources":["../../../src/core/pkce/cookieOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,oDAAoD;AACpD,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AAEpD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,WAAW,CAAC,EAAE,MAAM,GACnB,aAAa,CAuBf"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Name of the PKCE verifier cookie on the wire. */
|
|
2
|
+
export const PKCE_COOKIE_NAME = 'wos-auth-verifier';
|
|
3
|
+
/**
|
|
4
|
+
* PKCE verifier cookie lifetime (seconds). Matches the 10-minute convention
|
|
5
|
+
* used by Arctic, openid-client, Clerk, and Okta for short-lived OAuth state
|
|
6
|
+
* cookies — long enough to accommodate slow sign-ins (out-of-band 2FA, tab
|
|
7
|
+
* switching) and short enough to keep the replay window tight if the sealed
|
|
8
|
+
* blob leaks.
|
|
9
|
+
*
|
|
10
|
+
* The same value is used as both the `Max-Age` cookie attribute and the
|
|
11
|
+
* sealed payload's TTL, so both layers reject a stale blob.
|
|
12
|
+
*/
|
|
13
|
+
export const PKCE_COOKIE_MAX_AGE = 600;
|
|
14
|
+
/**
|
|
15
|
+
* Compute PKCE verifier cookie options from config + the resolved redirect URI.
|
|
16
|
+
*
|
|
17
|
+
* Behavior:
|
|
18
|
+
* - `sameSite: 'strict'` is downgraded to `'lax'` so the cookie survives the
|
|
19
|
+
* cross-site redirect back from WorkOS.
|
|
20
|
+
* - `sameSite: 'none'` is preserved (iframe/embed flows require it).
|
|
21
|
+
* - `secure` is forced to `true` when `sameSite === 'none'` (required by
|
|
22
|
+
* modern browsers). Otherwise it is inferred from the redirect URI's
|
|
23
|
+
* protocol, defaulting fail-closed to `true` on invalid/missing URLs.
|
|
24
|
+
* - `path` is always `/`. The cookie gets sent on every same-origin request
|
|
25
|
+
* during the 10-minute window, which is fine — it's HttpOnly and expires
|
|
26
|
+
* quickly. The tradeoff favors DX: path-scoped cookies are invisible in
|
|
27
|
+
* Chrome DevTools' Application panel from any page outside the scoped
|
|
28
|
+
* path, which makes PKCE wiring look broken even when it works.
|
|
29
|
+
*
|
|
30
|
+
* Internal helper — not exported from the package. Callers get cookie options
|
|
31
|
+
* indirectly via `AuthService.createSignIn` / `clearPendingVerifier`.
|
|
32
|
+
*/
|
|
33
|
+
export function getPKCECookieOptions(config, redirectUri) {
|
|
34
|
+
const configuredSameSite = (config.cookieSameSite ?? 'lax').toLowerCase();
|
|
35
|
+
const sameSite = configuredSameSite === 'none' ? 'none' : 'lax';
|
|
36
|
+
const urlString = redirectUri ?? config.redirectUri;
|
|
37
|
+
let secure = true;
|
|
38
|
+
if (urlString && sameSite !== 'none') {
|
|
39
|
+
try {
|
|
40
|
+
secure = new URL(urlString).protocol === 'https:';
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Fail-closed: secure stays true.
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
path: '/',
|
|
48
|
+
httpOnly: true,
|
|
49
|
+
secure,
|
|
50
|
+
sameSite,
|
|
51
|
+
maxAge: PKCE_COOKIE_MAX_AGE,
|
|
52
|
+
...(config.cookieDomain ? { domain: config.cookieDomain } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=cookieOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieOptions.js","sourceRoot":"","sources":["../../../src/core/pkce/cookieOptions.ts"],"names":[],"mappings":"AAGA,oDAAoD;AACpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAqB,EACrB,WAAoB;IAEpB,MAAM,kBAAkB,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1E,MAAM,QAAQ,GACZ,kBAAkB,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IAEjD,MAAM,SAAS,GAAG,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC;IACpD,IAAI,MAAM,GAAG,IAAI,CAAC;IAClB,IAAI,SAAS,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;QACrC,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC;QACpD,CAAC;QAAC,MAAM,CAAC;YACP,kCAAkC;QACpC,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,GAAG;QACT,QAAQ,EAAE,IAAI;QACd,MAAM;QACN,QAAQ;QACR,MAAM,EAAE,mBAAmB;QAC3B,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { WorkOS } from '@workos-inc/node';
|
|
2
|
+
import type { AuthKitConfig } from '../config/types.js';
|
|
3
|
+
import type { CookieOptions, GetAuthorizationUrlOptions, SessionEncryption } from '../session/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Maximum UTF-8 byte length for caller-supplied `options.state`. Enforced
|
|
6
|
+
* as an early, user-facing check so large custom state fails with a clear
|
|
7
|
+
* error before any crypto work — ahead of the authoritative sealed-cookie
|
|
8
|
+
* length guard below.
|
|
9
|
+
*/
|
|
10
|
+
export declare const PKCE_MAX_STATE_BYTES = 2048;
|
|
11
|
+
/**
|
|
12
|
+
* Maximum serialized `Set-Cookie` header length (bytes) for the verifier.
|
|
13
|
+
* Browsers start dropping cookies past ~4096 bytes per RFC 6265; 3800
|
|
14
|
+
* leaves headroom for proxies that cap lower and for the handful of
|
|
15
|
+
* cookie attributes whose size isn't known until serialization time
|
|
16
|
+
* (notably `Domain=` when `cookieDomain` is set).
|
|
17
|
+
*/
|
|
18
|
+
export declare const PKCE_MAX_COOKIE_BYTES = 3800;
|
|
19
|
+
/**
|
|
20
|
+
* Internal authorization-URL generation result.
|
|
21
|
+
*
|
|
22
|
+
* Not exported: AuthService consumes `sealedState` + `cookieOptions` to write
|
|
23
|
+
* the verifier cookie via `storage.setCookie`, then returns only `{ url, response?, headers? }`
|
|
24
|
+
* to callers.
|
|
25
|
+
*/
|
|
26
|
+
export interface GeneratedAuthorizationUrl {
|
|
27
|
+
url: string;
|
|
28
|
+
sealedState: string;
|
|
29
|
+
cookieOptions: CookieOptions;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate a WorkOS authorization URL bound to a PKCE verifier.
|
|
33
|
+
*
|
|
34
|
+
* Returns the URL, the sealed state blob (used as both the OAuth `state`
|
|
35
|
+
* query param AND the cookie value — identical string; the callback does a
|
|
36
|
+
* byte-compare before decrypting), and the cookie options the verifier
|
|
37
|
+
* cookie should be written with.
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateAuthorizationUrl(params: {
|
|
40
|
+
client: WorkOS;
|
|
41
|
+
config: AuthKitConfig;
|
|
42
|
+
encryption: SessionEncryption;
|
|
43
|
+
options: GetAuthorizationUrlOptions;
|
|
44
|
+
}): Promise<GeneratedAuthorizationUrl>;
|
|
45
|
+
//# sourceMappingURL=generateAuthorizationUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateAuthorizationUrl.d.ts","sourceRoot":"","sources":["../../../src/core/pkce/generateAuthorizationUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EACV,aAAa,EACb,0BAA0B,EAC1B,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAI7B;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,aAAa,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,wBAAsB,wBAAwB,CAAC,MAAM,EAAE;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,0BAA0B,CAAC;CACrC,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAmErC"}
|