@sixb/server 0.1.1 → 0.1.2
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 +3 -3
- package/dist/auth/application-access.d.ts +2 -2
- package/dist/auth/application-access.d.ts.map +1 -1
- package/dist/auth/connector-callback-cookie.d.ts +12 -0
- package/dist/auth/connector-callback-cookie.d.ts.map +1 -0
- package/dist/auth/guard.d.ts +3 -3
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +13 -27
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts +2 -2
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +16 -0
- package/dist/connectors/http.d.ts.map +1 -0
- package/dist/index.js +3293 -2704
- package/dist/index.js.map +55 -50
- package/dist/openapi/tags.d.ts +11 -3
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +6 -2
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +21 -31
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +9 -8
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts +2 -2
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +130 -131
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +84 -84
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +794 -0
- package/dist/routes/connector-connection-runs.d.ts.map +1 -0
- package/dist/routes/connector-connections.d.ts +219 -0
- package/dist/routes/connector-connections.d.ts.map +1 -0
- package/dist/routes/connectors.d.ts +10 -4
- package/dist/routes/connectors.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +8 -4
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +8 -8
- package/dist/routes/events.d.ts.map +1 -1
- package/dist/routes/files.d.ts +11 -10
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/links.d.ts +2 -2
- package/dist/routes/links.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +5 -5
- package/dist/routes/logs.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +34 -34
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +50 -50
- package/dist/routes/ontology.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +24 -34
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/project.d.ts +2 -2
- package/dist/routes/project.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +131 -83
- package/dist/routes/projections.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +6 -6
- package/dist/routes/rules.d.ts.map +1 -1
- package/dist/routes/status.d.ts +2 -2
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +20 -25
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +2 -2
- package/dist/routes/telemetry.d.ts.map +1 -1
- package/dist/routes/webhook-runs.d.ts +9 -9
- package/dist/routes/webhook-runs.d.ts.map +1 -1
- package/dist/routes/webhooks.d.ts +2 -2
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +74 -48
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/agents.d.ts +11 -5
- package/dist/routes/ws/agents.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +8 -8
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/log-subscription-hub.d.ts +6 -3
- package/dist/routes/ws/log-subscription-hub.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/logs.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +97 -202
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +442 -439
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-usage.d.ts +34 -0
- package/dist/schemas/ai-usage.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +142 -142
- package/dist/schemas/common.d.ts +37 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +713 -2
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +2 -2
- package/dist/schemas/event-payloads.d.ts +6 -6
- package/dist/schemas/events.d.ts +34 -34
- package/dist/schemas/logs.d.ts +22 -22
- package/dist/schemas/objects.d.ts +10 -10
- package/dist/schemas/ontology.d.ts +118 -118
- package/dist/schemas/pipelines.d.ts +95 -190
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +918 -563
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/status.d.ts +2 -2
- package/dist/schemas/syncs.d.ts +65 -108
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/webhook-runs.d.ts +41 -41
- package/dist/schemas/webhook-runs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +516 -183
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +6 -6
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +2 -0
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +4 -3
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth/access-token-boundary.ts +4 -4
- package/src/auth/application-access.ts +8 -9
- package/src/auth/connector-callback-cookie.ts +95 -0
- package/src/auth/guard.ts +11 -11
- package/src/auth/public-routes.ts +13 -0
- package/src/auth/scope.ts +26 -36
- package/src/auth/session-cookies.ts +3 -3
- package/src/connectors/http.ts +110 -0
- package/src/openapi/tags.ts +9 -1
- package/src/registerRoutes.ts +34 -23
- package/src/routes/action-runs.ts +39 -39
- package/src/routes/actions.ts +7 -13
- package/src/routes/agent-api-gateway.ts +41 -38
- package/src/routes/agents.ts +89 -200
- package/src/routes/auth.ts +87 -91
- package/src/routes/connector-connection-runs.ts +346 -0
- package/src/routes/connector-connections.ts +135 -0
- package/src/routes/connectors.ts +24 -12
- package/src/routes/datasets.ts +55 -54
- package/src/routes/events.ts +5 -5
- package/src/routes/files.ts +22 -30
- package/src/routes/links.ts +31 -35
- package/src/routes/logs.ts +6 -11
- package/src/routes/objects.ts +51 -114
- package/src/routes/ontology.ts +27 -38
- package/src/routes/pipelines.ts +28 -62
- package/src/routes/project.ts +3 -3
- package/src/routes/projections.ts +26 -38
- package/src/routes/rules.ts +11 -25
- package/src/routes/status.ts +5 -5
- package/src/routes/syncs.ts +19 -45
- package/src/routes/telemetry.ts +18 -29
- package/src/routes/webhook-runs.ts +5 -5
- package/src/routes/webhooks.ts +259 -341
- package/src/routes/workflows.ts +226 -248
- package/src/routes/ws/agents.ts +196 -66
- package/src/routes/ws/events.ts +11 -10
- package/src/routes/ws/log-subscription-hub.ts +6 -12
- package/src/routes/ws/logs.ts +13 -5
- package/src/schemas/actions.ts +58 -25
- package/src/schemas/agents.ts +19 -14
- package/src/schemas/ai-usage.ts +16 -0
- package/src/schemas/common.ts +24 -0
- package/src/schemas/connectors.ts +164 -0
- package/src/schemas/pipelines.ts +23 -15
- package/src/schemas/projections.ts +17 -3
- package/src/schemas/syncs.ts +13 -8
- package/src/schemas/webhook-runs.ts +10 -5
- package/src/schemas/workflows.ts +16 -6
- package/src/server.ts +65 -26
- package/src/utils/http.ts +34 -6
- package/src/utils/ws.ts +10 -5
package/src/routes/auth.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto"
|
|
2
|
-
import type { AuthSessionAudience, GroupDefinition,
|
|
2
|
+
import type { AuthSessionAudience, GroupDefinition, SixbHostView } from "@sixb/core"
|
|
3
3
|
import {
|
|
4
4
|
type AuthenticatedUserRequestSession,
|
|
5
5
|
type AuthRequestResult,
|
|
@@ -117,28 +117,24 @@ export interface AuthRoutesOptions {
|
|
|
117
117
|
) => AuthInvitationRedirectContext
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export function registerAuthRoutes(
|
|
121
|
-
app: Elysia,
|
|
122
|
-
sixb: Sixb<readonly OntologySource[]>,
|
|
123
|
-
options: AuthRoutesOptions
|
|
124
|
-
) {
|
|
120
|
+
export function registerAuthRoutes(app: Elysia, host: SixbHostView, options: AuthRoutesOptions) {
|
|
125
121
|
return app
|
|
126
122
|
.get(
|
|
127
123
|
"/api/auth/session",
|
|
128
124
|
async ({ request }) => {
|
|
129
125
|
const authOptions = resolveAuthOptions(options, request)
|
|
130
|
-
let session = await
|
|
126
|
+
let session = await host.auth.getSession(request, authOptions)
|
|
131
127
|
if (!session.authenticated) {
|
|
132
128
|
return jsonResponse({ authenticated: false as const }, 200)
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
let applicationAccessAllowed = sessionCanAccessApplication(
|
|
136
|
-
|
|
132
|
+
host,
|
|
137
133
|
session,
|
|
138
134
|
authOptions.audience
|
|
139
135
|
)
|
|
140
136
|
if (applicationAccessAllowed && hasForegroundSessionActivity(request)) {
|
|
141
|
-
session = await
|
|
137
|
+
session = await host.auth.getSession(request, {
|
|
142
138
|
...authOptions,
|
|
143
139
|
sessionActivity: "foreground",
|
|
144
140
|
})
|
|
@@ -146,13 +142,13 @@ export function registerAuthRoutes(
|
|
|
146
142
|
return jsonResponse({ authenticated: false as const }, 200)
|
|
147
143
|
}
|
|
148
144
|
applicationAccessAllowed = sessionCanAccessApplication(
|
|
149
|
-
|
|
145
|
+
host,
|
|
150
146
|
session,
|
|
151
147
|
authOptions.audience
|
|
152
148
|
)
|
|
153
149
|
}
|
|
154
150
|
|
|
155
|
-
const cookieOptions =
|
|
151
|
+
const cookieOptions = host.auth.getCookieOptions(authOptions)
|
|
156
152
|
const csrf = resolveSessionCsrfToken({
|
|
157
153
|
request,
|
|
158
154
|
cookieOptions,
|
|
@@ -161,7 +157,7 @@ export function registerAuthRoutes(
|
|
|
161
157
|
const renewal =
|
|
162
158
|
session.sessionRenewed === true
|
|
163
159
|
? createSessionRenewalCookieHeaders({
|
|
164
|
-
|
|
160
|
+
host,
|
|
165
161
|
request,
|
|
166
162
|
session,
|
|
167
163
|
csrfToken: csrf.token,
|
|
@@ -203,8 +199,8 @@ export function registerAuthRoutes(
|
|
|
203
199
|
"/api/auth/sign-out",
|
|
204
200
|
async ({ request }) => {
|
|
205
201
|
const authOptions = resolveAuthOptions(options, request)
|
|
206
|
-
const session = await
|
|
207
|
-
const cookieOptions =
|
|
202
|
+
const session = await host.auth.getSession(request, authOptions)
|
|
203
|
+
const cookieOptions = host.auth.getCookieOptions(authOptions)
|
|
208
204
|
if (
|
|
209
205
|
session.authenticated &&
|
|
210
206
|
!verifyDoubleSubmitCsrf(request, {
|
|
@@ -215,13 +211,13 @@ export function registerAuthRoutes(
|
|
|
215
211
|
}
|
|
216
212
|
|
|
217
213
|
if (session.authenticated) {
|
|
218
|
-
await
|
|
219
|
-
projectId:
|
|
214
|
+
await host.storage.auth?.sessions.revoke({
|
|
215
|
+
projectId: host.id,
|
|
220
216
|
id: session.session.id,
|
|
221
217
|
revokedAt: new Date(),
|
|
222
218
|
})
|
|
223
219
|
// Drop the cached session immediately so it isn't honored for the cache TTL.
|
|
224
|
-
|
|
220
|
+
host.auth.invalidateSession(session.session.id)
|
|
225
221
|
}
|
|
226
222
|
|
|
227
223
|
const headers = new Headers({ "content-type": "application/json; charset=utf-8" })
|
|
@@ -250,13 +246,13 @@ export function registerAuthRoutes(
|
|
|
250
246
|
"/api/auth/sessions",
|
|
251
247
|
async ({ request }) => {
|
|
252
248
|
const authOptions = resolveAuthOptions(options, request)
|
|
253
|
-
const session = await
|
|
249
|
+
const session = await host.auth.getSession(request, authOptions)
|
|
254
250
|
if (!session.authenticated) {
|
|
255
251
|
return jsonResponse({ error: "Authentication required" }, 401)
|
|
256
252
|
}
|
|
257
253
|
|
|
258
|
-
const sessions = await requireAuthStorage(
|
|
259
|
-
projectId:
|
|
254
|
+
const sessions = await requireAuthStorage(host).sessions.listActiveByUserId({
|
|
255
|
+
projectId: host.id,
|
|
260
256
|
userId: session.user.id,
|
|
261
257
|
now: new Date(),
|
|
262
258
|
})
|
|
@@ -293,8 +289,8 @@ export function registerAuthRoutes(
|
|
|
293
289
|
"/api/auth/sessions/:sessionId/revoke",
|
|
294
290
|
async ({ request, params }) => {
|
|
295
291
|
const authOptions = resolveAuthOptions(options, request)
|
|
296
|
-
const session = await
|
|
297
|
-
const cookieOptions =
|
|
292
|
+
const session = await host.auth.getSession(request, authOptions)
|
|
293
|
+
const cookieOptions = host.auth.getCookieOptions(authOptions)
|
|
298
294
|
if (!session.authenticated) {
|
|
299
295
|
return jsonResponse({ error: "Authentication required" }, 401)
|
|
300
296
|
}
|
|
@@ -303,16 +299,16 @@ export function registerAuthRoutes(
|
|
|
303
299
|
}
|
|
304
300
|
|
|
305
301
|
const { sessionId } = RevokeAuthSessionParamsSchema.parse(params)
|
|
306
|
-
const storage = requireAuthStorage(
|
|
307
|
-
const target = await storage.sessions.getById({ projectId:
|
|
302
|
+
const storage = requireAuthStorage(host)
|
|
303
|
+
const target = await storage.sessions.getById({ projectId: host.id, id: sessionId })
|
|
308
304
|
// Only the caller's own sessions are revocable. A missing or foreign
|
|
309
305
|
// session id returns the same 404 so it cannot probe other accounts.
|
|
310
306
|
if (!target || target.userId !== session.user.id) {
|
|
311
307
|
return jsonResponse({ error: "Session not found" }, 404)
|
|
312
308
|
}
|
|
313
309
|
|
|
314
|
-
await storage.sessions.revoke({ projectId:
|
|
315
|
-
|
|
310
|
+
await storage.sessions.revoke({ projectId: host.id, id: sessionId, revokedAt: new Date() })
|
|
311
|
+
host.auth.invalidateSession(sessionId)
|
|
316
312
|
|
|
317
313
|
const headers = new Headers({ "content-type": "application/json; charset=utf-8" })
|
|
318
314
|
// Revoking the session backing this request also clears its cookies.
|
|
@@ -346,8 +342,8 @@ export function registerAuthRoutes(
|
|
|
346
342
|
"/api/auth/sign-out-all",
|
|
347
343
|
async ({ request }) => {
|
|
348
344
|
const authOptions = resolveAuthOptions(options, request)
|
|
349
|
-
const session = await
|
|
350
|
-
const cookieOptions =
|
|
345
|
+
const session = await host.auth.getSession(request, authOptions)
|
|
346
|
+
const cookieOptions = host.auth.getCookieOptions(authOptions)
|
|
351
347
|
if (!session.authenticated) {
|
|
352
348
|
return jsonResponse({ error: "Authentication required" }, 401)
|
|
353
349
|
}
|
|
@@ -358,13 +354,13 @@ export function registerAuthRoutes(
|
|
|
358
354
|
// Global sign-out: revoke every active session for the user across all
|
|
359
355
|
// audiences. Other audiences' cookies remain client-side but their
|
|
360
356
|
// sessions are revoked, so the next request re-authenticates.
|
|
361
|
-
const revoked = await requireAuthStorage(
|
|
362
|
-
projectId:
|
|
357
|
+
const revoked = await requireAuthStorage(host).sessions.revokeActiveForUser({
|
|
358
|
+
projectId: host.id,
|
|
363
359
|
userId: session.user.id,
|
|
364
360
|
revokedAt: new Date(),
|
|
365
361
|
})
|
|
366
362
|
for (const revokedSession of revoked) {
|
|
367
|
-
|
|
363
|
+
host.auth.invalidateSession(revokedSession.id)
|
|
368
364
|
}
|
|
369
365
|
|
|
370
366
|
const headers = new Headers({ "content-type": "application/json; charset=utf-8" })
|
|
@@ -396,7 +392,7 @@ export function registerAuthRoutes(
|
|
|
396
392
|
try {
|
|
397
393
|
const authOptions = resolveAuthOptions(options, request)
|
|
398
394
|
const session = requireAuthenticatedUserSession(
|
|
399
|
-
await
|
|
395
|
+
await host.auth.getSession(request, {
|
|
400
396
|
...authOptions,
|
|
401
397
|
credentialSource: "any",
|
|
402
398
|
})
|
|
@@ -409,7 +405,7 @@ export function registerAuthRoutes(
|
|
|
409
405
|
|
|
410
406
|
return jsonResponse(
|
|
411
407
|
{
|
|
412
|
-
groups:
|
|
408
|
+
groups: host.definitions.security
|
|
413
409
|
.listGroups()
|
|
414
410
|
// V1 avoids privilege escalation by only offering groups the
|
|
415
411
|
// current session already has. Runtime token auth still
|
|
@@ -443,7 +439,7 @@ export function registerAuthRoutes(
|
|
|
443
439
|
try {
|
|
444
440
|
const authOptions = resolveAuthOptions(options, request)
|
|
445
441
|
const session = requireAuthenticatedUserSession(
|
|
446
|
-
await
|
|
442
|
+
await host.auth.getSession(request, {
|
|
447
443
|
...authOptions,
|
|
448
444
|
credentialSource: "any",
|
|
449
445
|
})
|
|
@@ -452,7 +448,7 @@ export function registerAuthRoutes(
|
|
|
452
448
|
return session
|
|
453
449
|
}
|
|
454
450
|
|
|
455
|
-
const { accessTokens } = await
|
|
451
|
+
const { accessTokens } = await host.auth.listPersonalAccessTokens(request, authOptions)
|
|
456
452
|
|
|
457
453
|
return jsonResponse(
|
|
458
454
|
{
|
|
@@ -487,7 +483,7 @@ export function registerAuthRoutes(
|
|
|
487
483
|
const authOptions = resolveAuthOptions(options, request)
|
|
488
484
|
const parsed = CreateAuthPersonalAccessTokenBodySchema.parse(body)
|
|
489
485
|
const session = requireAuthenticatedUserSession(
|
|
490
|
-
await
|
|
486
|
+
await host.auth.getSession(request, {
|
|
491
487
|
...authOptions,
|
|
492
488
|
credentialSource: "any",
|
|
493
489
|
})
|
|
@@ -497,7 +493,7 @@ export function registerAuthRoutes(
|
|
|
497
493
|
}
|
|
498
494
|
|
|
499
495
|
const expiresAt = parseRequiredFutureDate(parsed.expiresAt)
|
|
500
|
-
const result = await
|
|
496
|
+
const result = await host.auth.createPersonalAccessToken(
|
|
501
497
|
request,
|
|
502
498
|
{ name: parsed.name, expiresAt, groupIds: parsed.groupIds },
|
|
503
499
|
authOptions
|
|
@@ -541,7 +537,7 @@ export function registerAuthRoutes(
|
|
|
541
537
|
try {
|
|
542
538
|
const authOptions = resolveAuthOptions(options, request)
|
|
543
539
|
const session = requireAuthenticatedUserSession(
|
|
544
|
-
await
|
|
540
|
+
await host.auth.getSession(request, {
|
|
545
541
|
...authOptions,
|
|
546
542
|
credentialSource: "any",
|
|
547
543
|
})
|
|
@@ -551,7 +547,7 @@ export function registerAuthRoutes(
|
|
|
551
547
|
}
|
|
552
548
|
|
|
553
549
|
const { tokenId } = RevokeAuthAccessTokenParamsSchema.parse(params)
|
|
554
|
-
const result = await
|
|
550
|
+
const result = await host.auth.revokePersonalAccessToken(
|
|
555
551
|
request,
|
|
556
552
|
{ tokenId },
|
|
557
553
|
authOptions
|
|
@@ -591,11 +587,11 @@ export function registerAuthRoutes(
|
|
|
591
587
|
try {
|
|
592
588
|
const authOptions = resolveAuthOptions(options, request)
|
|
593
589
|
const session = requireAuthenticatedUserSession(
|
|
594
|
-
await
|
|
590
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
595
591
|
)
|
|
596
592
|
if (session instanceof Response) return session
|
|
597
593
|
|
|
598
|
-
const { serviceAccounts } = await
|
|
594
|
+
const { serviceAccounts } = await host.auth.listServiceAccounts(request, authOptions)
|
|
599
595
|
|
|
600
596
|
return jsonResponse(
|
|
601
597
|
{
|
|
@@ -631,11 +627,11 @@ export function registerAuthRoutes(
|
|
|
631
627
|
const authOptions = resolveAuthOptions(options, request)
|
|
632
628
|
const parsed = CreateAuthServiceAccountBodySchema.parse(body)
|
|
633
629
|
const session = requireAuthenticatedUserSession(
|
|
634
|
-
await
|
|
630
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
635
631
|
)
|
|
636
632
|
if (session instanceof Response) return session
|
|
637
633
|
|
|
638
|
-
const result = await
|
|
634
|
+
const result = await host.auth.createServiceAccount(
|
|
639
635
|
request,
|
|
640
636
|
{
|
|
641
637
|
id: parsed.id,
|
|
@@ -682,12 +678,12 @@ export function registerAuthRoutes(
|
|
|
682
678
|
try {
|
|
683
679
|
const authOptions = resolveAuthOptions(options, request)
|
|
684
680
|
const session = requireAuthenticatedUserSession(
|
|
685
|
-
await
|
|
681
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
686
682
|
)
|
|
687
683
|
if (session instanceof Response) return session
|
|
688
684
|
|
|
689
685
|
const { serviceAccountId } = AuthServiceAccountParamsSchema.parse(params)
|
|
690
|
-
const result = await
|
|
686
|
+
const result = await host.auth.disableServiceAccount(
|
|
691
687
|
request,
|
|
692
688
|
{ serviceAccountId },
|
|
693
689
|
authOptions
|
|
@@ -726,12 +722,12 @@ export function registerAuthRoutes(
|
|
|
726
722
|
try {
|
|
727
723
|
const authOptions = resolveAuthOptions(options, request)
|
|
728
724
|
const session = requireAuthenticatedUserSession(
|
|
729
|
-
await
|
|
725
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
730
726
|
)
|
|
731
727
|
if (session instanceof Response) return session
|
|
732
728
|
|
|
733
729
|
const { serviceAccountId } = AuthServiceAccountParamsSchema.parse(params)
|
|
734
|
-
const { serviceAccount, accessTokens } = await
|
|
730
|
+
const { serviceAccount, accessTokens } = await host.auth.listServiceAccountAccessTokens(
|
|
735
731
|
request,
|
|
736
732
|
{ serviceAccountId },
|
|
737
733
|
authOptions
|
|
@@ -774,12 +770,12 @@ export function registerAuthRoutes(
|
|
|
774
770
|
const parsedParams = AuthServiceAccountParamsSchema.parse(params)
|
|
775
771
|
const parsed = CreateAuthServiceAccountAccessTokenBodySchema.parse(body)
|
|
776
772
|
const session = requireAuthenticatedUserSession(
|
|
777
|
-
await
|
|
773
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
778
774
|
)
|
|
779
775
|
if (session instanceof Response) return session
|
|
780
776
|
|
|
781
777
|
const expiresAt = parseRequiredFutureDate(parsed.expiresAt)
|
|
782
|
-
const result = await
|
|
778
|
+
const result = await host.auth.createServiceAccountAccessToken(
|
|
783
779
|
request,
|
|
784
780
|
{
|
|
785
781
|
serviceAccountId: parsedParams.serviceAccountId,
|
|
@@ -829,11 +825,11 @@ export function registerAuthRoutes(
|
|
|
829
825
|
const authOptions = resolveAuthOptions(options, request)
|
|
830
826
|
const parsed = RevokeAuthServiceAccountAccessTokenParamsSchema.parse(params)
|
|
831
827
|
const session = requireAuthenticatedUserSession(
|
|
832
|
-
await
|
|
828
|
+
await host.auth.getSession(request, { ...authOptions, credentialSource: "any" })
|
|
833
829
|
)
|
|
834
830
|
if (session instanceof Response) return session
|
|
835
831
|
|
|
836
|
-
const result = await
|
|
832
|
+
const result = await host.auth.revokeServiceAccountAccessToken(
|
|
837
833
|
request,
|
|
838
834
|
{ serviceAccountId: parsed.serviceAccountId, tokenId: parsed.tokenId },
|
|
839
835
|
authOptions
|
|
@@ -882,7 +878,7 @@ export function registerAuthRoutes(
|
|
|
882
878
|
return deliveryContext
|
|
883
879
|
}
|
|
884
880
|
|
|
885
|
-
const result = await
|
|
881
|
+
const result = await host.auth.invite(
|
|
886
882
|
request,
|
|
887
883
|
{
|
|
888
884
|
email: parsed.email,
|
|
@@ -937,7 +933,7 @@ export function registerAuthRoutes(
|
|
|
937
933
|
const authOptions = resolveAuthOptions(options, request)
|
|
938
934
|
return jsonResponse(
|
|
939
935
|
{
|
|
940
|
-
...(await
|
|
936
|
+
...(await host.auth.getInvitationOptions(request, authOptions)),
|
|
941
937
|
...options.getInvitationDestinationOptions(request),
|
|
942
938
|
},
|
|
943
939
|
200
|
|
@@ -965,7 +961,7 @@ export function registerAuthRoutes(
|
|
|
965
961
|
try {
|
|
966
962
|
const authOptions = resolveAuthOptions(options, request)
|
|
967
963
|
const parsed = ListAuthInvitationsQuerySchema.parse(query)
|
|
968
|
-
const result = await
|
|
964
|
+
const result = await host.auth.listInvitations(
|
|
969
965
|
request,
|
|
970
966
|
{
|
|
971
967
|
email: parsed.email,
|
|
@@ -1012,7 +1008,7 @@ export function registerAuthRoutes(
|
|
|
1012
1008
|
try {
|
|
1013
1009
|
const authOptions = resolveAuthOptions(options, request)
|
|
1014
1010
|
const parsed = RevokeAuthInvitationParamsSchema.parse(params)
|
|
1015
|
-
const result = await
|
|
1011
|
+
const result = await host.auth.revokeInvitation(
|
|
1016
1012
|
request,
|
|
1017
1013
|
{
|
|
1018
1014
|
invitationId: parsed.invitationId,
|
|
@@ -1053,7 +1049,7 @@ export function registerAuthRoutes(
|
|
|
1053
1049
|
async ({ request }) => {
|
|
1054
1050
|
try {
|
|
1055
1051
|
const authOptions = resolveAuthOptions(options, request)
|
|
1056
|
-
return jsonResponse(await
|
|
1052
|
+
return jsonResponse(await host.auth.getMembershipOptions(request, authOptions), 200)
|
|
1057
1053
|
} catch (error) {
|
|
1058
1054
|
return authRouteErrorResponse(error)
|
|
1059
1055
|
}
|
|
@@ -1077,7 +1073,7 @@ export function registerAuthRoutes(
|
|
|
1077
1073
|
try {
|
|
1078
1074
|
const authOptions = resolveAuthOptions(options, request)
|
|
1079
1075
|
const parsed = ListAuthMembersQuerySchema.parse(query)
|
|
1080
|
-
const result = await
|
|
1076
|
+
const result = await host.auth.listMembers(
|
|
1081
1077
|
request,
|
|
1082
1078
|
{
|
|
1083
1079
|
limit: parseOptionalInt(parsed.limit),
|
|
@@ -1121,7 +1117,7 @@ export function registerAuthRoutes(
|
|
|
1121
1117
|
const authOptions = resolveAuthOptions(options, request)
|
|
1122
1118
|
const parsedParams = AuthMemberParamsSchema.parse(params)
|
|
1123
1119
|
const parsed = UpdateAuthMemberGroupsBodySchema.parse(body)
|
|
1124
|
-
const result = await
|
|
1120
|
+
const result = await host.auth.updateMemberGroups(
|
|
1125
1121
|
request,
|
|
1126
1122
|
{ userId: parsedParams.userId, groupIds: parsed.groupIds },
|
|
1127
1123
|
authOptions
|
|
@@ -1157,7 +1153,7 @@ export function registerAuthRoutes(
|
|
|
1157
1153
|
try {
|
|
1158
1154
|
const authOptions = resolveAuthOptions(options, request)
|
|
1159
1155
|
const parsed = AuthMemberParamsSchema.parse(params)
|
|
1160
|
-
const result = await
|
|
1156
|
+
const result = await host.auth.suspendMember(
|
|
1161
1157
|
request,
|
|
1162
1158
|
{ userId: parsed.userId },
|
|
1163
1159
|
authOptions
|
|
@@ -1191,7 +1187,7 @@ export function registerAuthRoutes(
|
|
|
1191
1187
|
try {
|
|
1192
1188
|
const authOptions = resolveAuthOptions(options, request)
|
|
1193
1189
|
const parsed = AuthMemberParamsSchema.parse(params)
|
|
1194
|
-
const result = await
|
|
1190
|
+
const result = await host.auth.reactivateMember(
|
|
1195
1191
|
request,
|
|
1196
1192
|
{ userId: parsed.userId },
|
|
1197
1193
|
authOptions
|
|
@@ -1222,7 +1218,7 @@ export function registerAuthRoutes(
|
|
|
1222
1218
|
.post(
|
|
1223
1219
|
"/auth/sign-in",
|
|
1224
1220
|
async ({ body, request }) => {
|
|
1225
|
-
const strategy =
|
|
1221
|
+
const strategy = host.auth.getStrategy()
|
|
1226
1222
|
const authRedirect = resolveAuthRedirectContext(options, request, {
|
|
1227
1223
|
audience: body.audience,
|
|
1228
1224
|
returnTo: body.returnTo,
|
|
@@ -1231,12 +1227,12 @@ export function registerAuthRoutes(
|
|
|
1231
1227
|
return authRedirect
|
|
1232
1228
|
}
|
|
1233
1229
|
|
|
1234
|
-
const authStorage = requireAuthStorage(
|
|
1230
|
+
const authStorage = requireAuthStorage(host)
|
|
1235
1231
|
|
|
1236
1232
|
if (isMagicLinkAuthStrategy(strategy)) {
|
|
1237
1233
|
const pending = createMagicLinkPendingCredential()
|
|
1238
1234
|
const result = await strategy.requestMagicLink({
|
|
1239
|
-
projectId:
|
|
1235
|
+
projectId: host.id,
|
|
1240
1236
|
authStorage,
|
|
1241
1237
|
email: body.email ?? "",
|
|
1242
1238
|
audience: authRedirect.audience,
|
|
@@ -1263,7 +1259,7 @@ export function registerAuthRoutes(
|
|
|
1263
1259
|
"set-cookie",
|
|
1264
1260
|
magicLinkPendingCookieHeader({
|
|
1265
1261
|
request,
|
|
1266
|
-
|
|
1262
|
+
host,
|
|
1267
1263
|
value: result.status === "sent" ? pending.secret : existingPending || pending.secret,
|
|
1268
1264
|
maxAgeSeconds: magicLinkPendingCookieMaxAgeSeconds(strategy),
|
|
1269
1265
|
})
|
|
@@ -1273,7 +1269,7 @@ export function registerAuthRoutes(
|
|
|
1273
1269
|
|
|
1274
1270
|
if (isOidcAuthStrategy(strategy)) {
|
|
1275
1271
|
const result = await strategy.startOidcSignIn({
|
|
1276
|
-
projectId:
|
|
1272
|
+
projectId: host.id,
|
|
1277
1273
|
authStorage,
|
|
1278
1274
|
audience: authRedirect.audience,
|
|
1279
1275
|
returnTo: authRedirect.returnTo,
|
|
@@ -1297,7 +1293,7 @@ export function registerAuthRoutes(
|
|
|
1297
1293
|
.get(
|
|
1298
1294
|
"/auth/sign-in",
|
|
1299
1295
|
async ({ request }) => {
|
|
1300
|
-
const strategy =
|
|
1296
|
+
const strategy = host.auth.getStrategy()
|
|
1301
1297
|
const url = new URL(request.url)
|
|
1302
1298
|
const authRedirect = resolveAuthRedirectContext(options, request, {
|
|
1303
1299
|
audience: url.searchParams.get("audience"),
|
|
@@ -1313,8 +1309,8 @@ export function registerAuthRoutes(
|
|
|
1313
1309
|
|
|
1314
1310
|
if (isOidcAuthStrategy(strategy)) {
|
|
1315
1311
|
const result = await strategy.startOidcSignIn({
|
|
1316
|
-
projectId:
|
|
1317
|
-
authStorage: requireAuthStorage(
|
|
1312
|
+
projectId: host.id,
|
|
1313
|
+
authStorage: requireAuthStorage(host),
|
|
1318
1314
|
audience: authRedirect.audience,
|
|
1319
1315
|
returnTo: authRedirect.returnTo,
|
|
1320
1316
|
requestOrigin: authRedirect.requestOrigin,
|
|
@@ -1329,7 +1325,7 @@ export function registerAuthRoutes(
|
|
|
1329
1325
|
.get(
|
|
1330
1326
|
"/auth/callback",
|
|
1331
1327
|
async ({ request }) => {
|
|
1332
|
-
const strategy =
|
|
1328
|
+
const strategy = host.auth.getStrategy()
|
|
1333
1329
|
|
|
1334
1330
|
if (isMagicLinkAuthStrategy(strategy)) {
|
|
1335
1331
|
const url = new URL(request.url)
|
|
@@ -1351,8 +1347,8 @@ export function registerAuthRoutes(
|
|
|
1351
1347
|
if (strategy.peekMagicLink) {
|
|
1352
1348
|
try {
|
|
1353
1349
|
const peeked = await strategy.peekMagicLink({
|
|
1354
|
-
projectId:
|
|
1355
|
-
authStorage: requireAuthStorage(
|
|
1350
|
+
projectId: host.id,
|
|
1351
|
+
authStorage: requireAuthStorage(host),
|
|
1356
1352
|
magicLinkId,
|
|
1357
1353
|
token,
|
|
1358
1354
|
})
|
|
@@ -1377,7 +1373,7 @@ export function registerAuthRoutes(
|
|
|
1377
1373
|
matchesMagicLinkRequester(pendingSecret, requesterHash)
|
|
1378
1374
|
) {
|
|
1379
1375
|
return completeMagicLinkCallback({
|
|
1380
|
-
|
|
1376
|
+
host,
|
|
1381
1377
|
strategy,
|
|
1382
1378
|
options,
|
|
1383
1379
|
request,
|
|
@@ -1398,8 +1394,8 @@ export function registerAuthRoutes(
|
|
|
1398
1394
|
try {
|
|
1399
1395
|
const authOptions = resolveAuthOptions(options, request)
|
|
1400
1396
|
const result = await strategy.completeOidcSignIn({
|
|
1401
|
-
projectId:
|
|
1402
|
-
authStorage: requireAuthStorage(
|
|
1397
|
+
projectId: host.id,
|
|
1398
|
+
authStorage: requireAuthStorage(host),
|
|
1403
1399
|
requestUrl: request.url,
|
|
1404
1400
|
requestOrigin: options.resolveAuthRequestOrigin(request),
|
|
1405
1401
|
session: {
|
|
@@ -1407,13 +1403,13 @@ export function registerAuthRoutes(
|
|
|
1407
1403
|
audience: authOptions.audience,
|
|
1408
1404
|
tokenHash: sessionCredential.tokenHash,
|
|
1409
1405
|
createdAt: now,
|
|
1410
|
-
...
|
|
1406
|
+
...host.auth.createSessionDeadlines(now),
|
|
1411
1407
|
...device,
|
|
1412
1408
|
},
|
|
1413
1409
|
})
|
|
1414
1410
|
|
|
1415
1411
|
return sessionCallbackCompletionResponse({
|
|
1416
|
-
|
|
1412
|
+
host,
|
|
1417
1413
|
request,
|
|
1418
1414
|
apiOrigin: options.resolveAuthRequestOrigin(request),
|
|
1419
1415
|
sessionCredential,
|
|
@@ -1434,7 +1430,7 @@ export function registerAuthRoutes(
|
|
|
1434
1430
|
.post(
|
|
1435
1431
|
"/auth/callback",
|
|
1436
1432
|
async ({ body, request }) => {
|
|
1437
|
-
const strategy =
|
|
1433
|
+
const strategy = host.auth.getStrategy()
|
|
1438
1434
|
|
|
1439
1435
|
if (!isMagicLinkAuthStrategy(strategy)) {
|
|
1440
1436
|
return strategyNotImplementedResponse("Auth callback is not implemented yet.")
|
|
@@ -1446,7 +1442,7 @@ export function registerAuthRoutes(
|
|
|
1446
1442
|
return htmlMessageResponse("This sign-in link is invalid or expired.", 400)
|
|
1447
1443
|
}
|
|
1448
1444
|
|
|
1449
|
-
return completeMagicLinkCallback({
|
|
1445
|
+
return completeMagicLinkCallback({ host, strategy, options, request, magicLinkId, token })
|
|
1450
1446
|
},
|
|
1451
1447
|
{
|
|
1452
1448
|
body: t.Object({
|
|
@@ -1497,7 +1493,7 @@ function matchesMagicLinkRequester(pendingSecret: string, requesterHash: string)
|
|
|
1497
1493
|
// navigation and the cookie must accompany that GET for the fast path to work.
|
|
1498
1494
|
function magicLinkPendingCookieHeader(params: {
|
|
1499
1495
|
readonly request: Request
|
|
1500
|
-
readonly
|
|
1496
|
+
readonly host: SixbHostView
|
|
1501
1497
|
readonly value: string
|
|
1502
1498
|
readonly maxAgeSeconds: number
|
|
1503
1499
|
}): string {
|
|
@@ -1508,7 +1504,7 @@ function magicLinkPendingCookieHeader(params: {
|
|
|
1508
1504
|
"HttpOnly",
|
|
1509
1505
|
`Max-Age=${params.maxAgeSeconds}`,
|
|
1510
1506
|
]
|
|
1511
|
-
if (shouldUseSecureCookies(params.request, params.
|
|
1507
|
+
if (shouldUseSecureCookies(params.request, params.host.auth.getCookieOptions())) {
|
|
1512
1508
|
parts.push("Secure")
|
|
1513
1509
|
}
|
|
1514
1510
|
return parts.join("; ")
|
|
@@ -1517,7 +1513,7 @@ function magicLinkPendingCookieHeader(params: {
|
|
|
1517
1513
|
// Shared by POST /auth/callback (confirmation click) and the same-device fast
|
|
1518
1514
|
// path on GET. Consumes the single-use token and mints the session cookies.
|
|
1519
1515
|
async function completeMagicLinkCallback(input: {
|
|
1520
|
-
readonly
|
|
1516
|
+
readonly host: SixbHostView
|
|
1521
1517
|
readonly strategy: MagicLinkAuthStrategy
|
|
1522
1518
|
readonly options: AuthRoutesOptions
|
|
1523
1519
|
readonly request: Request
|
|
@@ -1532,8 +1528,8 @@ async function completeMagicLinkCallback(input: {
|
|
|
1532
1528
|
|
|
1533
1529
|
try {
|
|
1534
1530
|
const result = await input.strategy.completeMagicLinkSignIn({
|
|
1535
|
-
projectId: input.
|
|
1536
|
-
authStorage: requireAuthStorage(input.
|
|
1531
|
+
projectId: input.host.id,
|
|
1532
|
+
authStorage: requireAuthStorage(input.host),
|
|
1537
1533
|
magicLinkId: input.magicLinkId,
|
|
1538
1534
|
token: input.token,
|
|
1539
1535
|
session: {
|
|
@@ -1541,13 +1537,13 @@ async function completeMagicLinkCallback(input: {
|
|
|
1541
1537
|
audience: authOptions.audience,
|
|
1542
1538
|
tokenHash: sessionCredential.tokenHash,
|
|
1543
1539
|
createdAt: now,
|
|
1544
|
-
...input.
|
|
1540
|
+
...input.host.auth.createSessionDeadlines(now),
|
|
1545
1541
|
...device,
|
|
1546
1542
|
},
|
|
1547
1543
|
})
|
|
1548
1544
|
|
|
1549
1545
|
const response = sessionCallbackCompletionResponse({
|
|
1550
|
-
|
|
1546
|
+
host: input.host,
|
|
1551
1547
|
request: input.request,
|
|
1552
1548
|
apiOrigin: input.options.resolveAuthRequestOrigin(input.request),
|
|
1553
1549
|
sessionCredential,
|
|
@@ -1560,7 +1556,7 @@ async function completeMagicLinkCallback(input: {
|
|
|
1560
1556
|
"set-cookie",
|
|
1561
1557
|
magicLinkPendingCookieHeader({
|
|
1562
1558
|
request: input.request,
|
|
1563
|
-
|
|
1559
|
+
host: input.host,
|
|
1564
1560
|
value: "",
|
|
1565
1561
|
maxAgeSeconds: 0,
|
|
1566
1562
|
})
|
|
@@ -1589,7 +1585,7 @@ function resolveSessionDevice(request: Request): {
|
|
|
1589
1585
|
}
|
|
1590
1586
|
|
|
1591
1587
|
function sessionCallbackCompletionResponse(input: {
|
|
1592
|
-
readonly
|
|
1588
|
+
readonly host: SixbHostView
|
|
1593
1589
|
readonly request: Request
|
|
1594
1590
|
readonly apiOrigin: string
|
|
1595
1591
|
readonly sessionCredential: ReturnType<typeof createSessionCredential>
|
|
@@ -1597,7 +1593,7 @@ function sessionCallbackCompletionResponse(input: {
|
|
|
1597
1593
|
readonly expiresAt: Date
|
|
1598
1594
|
readonly returnTo: string
|
|
1599
1595
|
}): Response {
|
|
1600
|
-
const cookieOptions = input.
|
|
1596
|
+
const cookieOptions = input.host.auth.getCookieOptions({ audience: input.audience })
|
|
1601
1597
|
const headers = new Headers({
|
|
1602
1598
|
"cache-control": "no-store",
|
|
1603
1599
|
})
|
|
@@ -2008,12 +2004,12 @@ function htmlMessageResponse(message: string, status = 200, heading?: string): R
|
|
|
2008
2004
|
)
|
|
2009
2005
|
}
|
|
2010
2006
|
|
|
2011
|
-
function requireAuthStorage(
|
|
2012
|
-
if (!
|
|
2007
|
+
function requireAuthStorage(host: SixbHostView): AuthStorage {
|
|
2008
|
+
if (!host.storage.auth) {
|
|
2013
2009
|
throw new Error("[SixbServer] Auth storage is required for auth routes.")
|
|
2014
2010
|
}
|
|
2015
2011
|
|
|
2016
|
-
return
|
|
2012
|
+
return host.storage.auth
|
|
2017
2013
|
}
|
|
2018
2014
|
|
|
2019
2015
|
function serializeGroupOption(group: GroupDefinition) {
|