@absolutejs/auth 0.65.5 → 0.66.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.
Files changed (61) hide show
  1. package/dist/agents/context.d.ts +5 -18
  2. package/dist/agents/index.js +3 -3
  3. package/dist/agents/index.js.map +3 -3
  4. package/dist/agents/routes.d.ts +24 -56
  5. package/dist/apikeys/routes.d.ts +169 -78
  6. package/dist/authContext.d.ts +34 -79
  7. package/dist/authorization/protectPermission.d.ts +11 -23
  8. package/dist/cli/migrate.js +2 -2
  9. package/dist/cli/migrate.js.map +4 -4
  10. package/dist/compliance/routes.d.ts +179 -54
  11. package/dist/credentials/emailVerification.d.ts +173 -56
  12. package/dist/credentials/login.d.ts +192 -63
  13. package/dist/credentials/passwordReset.d.ts +171 -60
  14. package/dist/credentials/register.d.ts +182 -41
  15. package/dist/credentials/routes.d.ts +46 -36
  16. package/dist/htmx/configuredRoutes.d.ts +263 -114
  17. package/dist/htmx/routes.d.ts +261 -89
  18. package/dist/index.d.ts +663 -443
  19. package/dist/index.js +475 -448
  20. package/dist/index.js.map +48 -48
  21. package/dist/manifest.js +86 -4
  22. package/dist/manifest.js.map +3 -3
  23. package/dist/mfa/challenge.d.ts +189 -59
  24. package/dist/mfa/management.d.ts +179 -54
  25. package/dist/mfa/routes.d.ts +34 -40
  26. package/dist/mfa/sms.d.ts +187 -59
  27. package/dist/mfa/totp.d.ts +187 -57
  28. package/dist/oidc/routes.d.ts +73 -74
  29. package/dist/oidc/vciRoutes.d.ts +9 -45
  30. package/dist/organizations/routes.d.ts +215 -77
  31. package/dist/passwordless/routes.d.ts +22 -34
  32. package/dist/portal/routes.d.ts +162 -55
  33. package/dist/roles/routes.d.ts +198 -67
  34. package/dist/routes/authorize.d.ts +182 -90
  35. package/dist/routes/callback.d.ts +189 -38
  36. package/dist/routes/profile.d.ts +177 -51
  37. package/dist/routes/protectRoute.d.ts +11 -23
  38. package/dist/routes/refresh.d.ts +177 -51
  39. package/dist/routes/requireAuth.d.ts +9 -21
  40. package/dist/routes/revoke.d.ts +177 -51
  41. package/dist/routes/sessions.d.ts +187 -61
  42. package/dist/routes/signout.d.ts +174 -50
  43. package/dist/routes/stepUp.d.ts +11 -23
  44. package/dist/routes/userStatus.d.ts +174 -52
  45. package/dist/scim/routes.d.ts +208 -73
  46. package/dist/server.js +475 -448
  47. package/dist/server.js.map +48 -48
  48. package/dist/session/cleanup.d.ts +5 -18
  49. package/dist/session/state.d.ts +3 -23
  50. package/dist/sso/discoveryRoute.d.ts +158 -52
  51. package/dist/sso/oidcRoutes.d.ts +211 -59
  52. package/dist/sso/samlIdpRoutes.d.ts +175 -46
  53. package/dist/sso/samlRoutes.d.ts +217 -69
  54. package/dist/typebox.d.ts +4 -4
  55. package/dist/types.d.ts +3 -5
  56. package/dist/vault/index.js +3 -3
  57. package/dist/vault/index.js.map +3 -3
  58. package/dist/vc/statusListRoutes.d.ts +158 -52
  59. package/dist/vc/vpRoutes.d.ts +170 -66
  60. package/dist/webauthn/routes.d.ts +199 -66
  61. package/package.json +8 -120
package/dist/index.js CHANGED
@@ -77,8 +77,8 @@ var DEFAULT_TOKEN_BYTES = 32, AES_KEY_BYTES = 32, AES_IV_BYTES = 12, HOTP_COUNTE
77
77
  const digest = await crypto.subtle.digest("SHA-256", textEncoder.encode(input));
78
78
  return new Uint8Array(digest);
79
79
  }, hmacSha1 = async (key, message) => {
80
- const cryptoKey = await crypto.subtle.importKey("raw", key, { hash: "SHA-1", name: "HMAC" }, false, ["sign"]);
81
- const signature = await crypto.subtle.sign("HMAC", cryptoKey, message);
80
+ const cryptoKey = await crypto.subtle.importKey("raw", Uint8Array.from(key), { hash: "SHA-1", name: "HMAC" }, false, ["sign"]);
81
+ const signature = await crypto.subtle.sign("HMAC", cryptoKey, Uint8Array.from(message));
82
82
  return new Uint8Array(signature);
83
83
  }, counterToBytes = (counter) => {
84
84
  const bytes = new Uint8Array(HOTP_COUNTER_BYTES);
@@ -3159,7 +3159,14 @@ var apiKeysRoutes = ({
3159
3159
  if (apiClientStore === undefined || accessTokenStore === undefined) {
3160
3160
  return new Elysia;
3161
3161
  }
3162
- return new Elysia().post(tokenRoute, async ({ body, headers }) => {
3162
+ return new Elysia().post(tokenRoute, {
3163
+ body: t.Object({
3164
+ client_id: t.Optional(t.String()),
3165
+ client_secret: t.Optional(t.String()),
3166
+ grant_type: t.Optional(t.String()),
3167
+ scope: t.Optional(t.String())
3168
+ })
3169
+ }, async ({ body, headers }) => {
3163
3170
  if (body.grant_type !== GRANT_CLIENT_CREDENTIALS) {
3164
3171
  return oauthError(HTTP_BAD_REQUEST, "unsupported_grant_type");
3165
3172
  }
@@ -3192,13 +3199,6 @@ var apiKeysRoutes = ({
3192
3199
  },
3193
3200
  status: HTTP_OK
3194
3201
  });
3195
- }, {
3196
- body: t.Object({
3197
- client_id: t.Optional(t.String()),
3198
- client_secret: t.Optional(t.String()),
3199
- grant_type: t.Optional(t.String()),
3200
- scope: t.Optional(t.String())
3201
- })
3202
3202
  });
3203
3203
  };
3204
3204
 
@@ -4546,14 +4546,10 @@ var loadSessionFromSource = async ({
4546
4546
 
4547
4547
  // src/session/state.ts
4548
4548
  import { Elysia as Elysia4 } from "elysia";
4549
- var sessionStore = () => {
4550
- const initialSession = {};
4551
- const initialUnregisteredSession = {};
4552
- return new Elysia4({ name: "sessionStore" }).state({
4553
- session: initialSession,
4554
- unregisteredSession: initialUnregisteredSession
4555
- });
4556
- };
4549
+ var sessionStore = (initialSession = {}, initialUnregisteredSession = {}) => new Elysia4({ name: "sessionStore" }).state({
4550
+ session: initialSession,
4551
+ unregisteredSession: initialUnregisteredSession
4552
+ });
4557
4553
 
4558
4554
  // src/typebox.ts
4559
4555
  import { t as t2 } from "elysia";
@@ -4574,7 +4570,10 @@ var protectPermissionPlugin = ({
4574
4570
  }) => new Elysia5({
4575
4571
  name: "@absolutejs/auth/permission",
4576
4572
  seed: pluginDependencySeed(hasPermission)
4577
- }).use(sessionStore()).guard({ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4573
+ }).use(sessionStore()).guard({
4574
+ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
4575
+ schema: "merge"
4576
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4578
4577
  protectPermission: (check, handleAuth, handleAuthFail) => getStatusFromSource({
4579
4578
  authSessionStore,
4580
4579
  session,
@@ -4617,7 +4616,10 @@ var protectRoutePlugin = ({
4617
4616
  } = {}) => new Elysia6({
4618
4617
  name: "@absolutejs/auth/protect-route",
4619
4618
  seed: pluginDependencySeed(authSessionStore)
4620
- }).use(sessionStore()).guard({ cookie: t4.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4619
+ }).use(sessionStore()).guard({
4620
+ cookie: t4.Cookie({ user_session_id: userSessionIdTypebox }),
4621
+ schema: "merge"
4622
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4621
4623
  protectRoute: (handleAuth, handleAuthFail) => getStatusFromSource({
4622
4624
  authSessionStore,
4623
4625
  session,
@@ -4643,7 +4645,10 @@ var stepUpPlugin = ({
4643
4645
  } = {}) => new Elysia7({
4644
4646
  name: "@absolutejs/auth/step-up",
4645
4647
  seed: pluginDependencySeed(authSessionStore)
4646
- }).use(sessionStore()).guard({ cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4648
+ }).use(sessionStore()).guard({
4649
+ cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
4650
+ schema: "merge"
4651
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4647
4652
  requireRecentAuth: (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
4648
4653
  authSessionStore,
4649
4654
  session,
@@ -4689,7 +4694,7 @@ import { Elysia as Elysia9, t as t6 } from "elysia";
4689
4694
  init_constants();
4690
4695
 
4691
4696
  // src/types.ts
4692
- function isJsonValue(value) {
4697
+ var isJsonValue = (value) => {
4693
4698
  if (value === null || typeof value === "boolean" || typeof value === "string")
4694
4699
  return true;
4695
4700
  if (typeof value === "number")
@@ -4699,7 +4704,7 @@ function isJsonValue(value) {
4699
4704
  if (typeof value !== "object")
4700
4705
  return false;
4701
4706
  return Object.values(value).every(isJsonValue);
4702
- }
4707
+ };
4703
4708
  var parseJsonObject = (value) => {
4704
4709
  if (!isJsonValue(value) || value === null || Array.isArray(value) || typeof value !== "object")
4705
4710
  throw new TypeError("Expected a JSON object");
@@ -5053,7 +5058,7 @@ var complianceRoutes = ({
5053
5058
  emit,
5054
5059
  exportUserData,
5055
5060
  getUserId
5056
- }) => new Elysia9().use(sessionStore()).get(`${complianceRoute}/export`, async ({
5061
+ }) => new Elysia9().use(sessionStore()).get(`${complianceRoute}/export`, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
5057
5062
  cookie: { user_session_id },
5058
5063
  status,
5059
5064
  store: { session }
@@ -5073,7 +5078,7 @@ var complianceRoutes = ({
5073
5078
  userId: getUserId?.(current.user)
5074
5079
  });
5075
5080
  return status("OK", data);
5076
- }, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(complianceRoute, async ({
5081
+ }).delete(complianceRoute, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
5077
5082
  cookie: { user_session_id },
5078
5083
  status,
5079
5084
  store: { session }
@@ -5106,7 +5111,7 @@ var complianceRoutes = ({
5106
5111
  userId
5107
5112
  });
5108
5113
  return status("OK", { deleted: true });
5109
- }, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) });
5114
+ });
5110
5115
 
5111
5116
  // src/credentials/routes.ts
5112
5117
  import { Elysia as Elysia14 } from "elysia";
@@ -5132,7 +5137,7 @@ var credentialsEmailVerification = ({
5132
5137
  requireEmailVerification = false,
5133
5138
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS,
5134
5139
  verifyEmailRoute = "/auth/verify-email"
5135
- }) => new Elysia10().post(verifyEmailRoute, async ({ body: { token }, status }) => {
5140
+ }) => new Elysia10().post(verifyEmailRoute, { body: t7.Object({ token: t7.String() }) }, async ({ body: { token }, status }) => {
5136
5141
  const consumed = await credentialStore.consumeVerificationToken(await hashToken(token));
5137
5142
  if (!consumed) {
5138
5143
  return status("Bad Request", "Invalid or expired verification token");
@@ -5172,7 +5177,7 @@ var credentialsEmailVerification = ({
5172
5177
  }
5173
5178
  await onEmailVerified?.({ email: consumed.email });
5174
5179
  return status("OK", { status: "email_verified" });
5175
- }, { body: t7.Object({ token: t7.String() }) }).post(`${verifyEmailRoute}/request`, async ({ body: { email }, status }) => {
5180
+ }).post(`${verifyEmailRoute}/request`, { body: t7.Object({ email: t7.String() }) }, async ({ body: { email }, status }) => {
5176
5181
  const normalizedEmail = email.trim().toLowerCase();
5177
5182
  const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
5178
5183
  if (credential && !credential.emailVerified) {
@@ -5191,7 +5196,7 @@ var credentialsEmailVerification = ({
5191
5196
  });
5192
5197
  }
5193
5198
  return status("OK", { status: "verification_requested" });
5194
- }, { body: t7.Object({ email: t7.String() }) });
5199
+ });
5195
5200
 
5196
5201
  // src/credentials/login.ts
5197
5202
  init_constants();
@@ -5305,7 +5310,7 @@ var constantTimeEqualBytes = (left, right) => {
5305
5310
  return diff === 0;
5306
5311
  };
5307
5312
  var base64Decode = (encoded) => new Uint8Array(Buffer.from(encoded, "base64"));
5308
- var sha256Bytes = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", input));
5313
+ var sha256Bytes = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", Uint8Array.from(input)));
5309
5314
  var isLegacyHash = (storedHash) => !storedHash.startsWith("$argon2id$") && !storedHash.startsWith("$2");
5310
5315
  var verifyAuth0Pbkdf2 = async (plainPassword, wrappedHash) => {
5311
5316
  const parts = wrappedHash.split(":");
@@ -5429,7 +5434,10 @@ var credentialsLogin = ({
5429
5434
  requireEmailVerification = false,
5430
5435
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
5431
5436
  trustedOrigins
5432
- }) => new Elysia11().use(sessionStore()).post(loginRoute, async ({
5437
+ }) => new Elysia11().use(sessionStore()).post(loginRoute, {
5438
+ body: t8.Object({ email: t8.String(), password: t8.String() }),
5439
+ cookie: t8.Cookie({ user_session_id: userSessionIdTypebox })
5440
+ }, async ({
5433
5441
  body: { email, password },
5434
5442
  cookie: { user_session_id },
5435
5443
  request,
@@ -5525,10 +5533,7 @@ var credentialsLogin = ({
5525
5533
  passwordCompromised,
5526
5534
  status: "authenticated"
5527
5535
  });
5528
- }), {
5529
- body: t8.Object({ email: t8.String(), password: t8.String() }),
5530
- cookie: t8.Cookie({ user_session_id: userSessionIdTypebox })
5531
- });
5536
+ }));
5532
5537
 
5533
5538
  // src/credentials/passwordReset.ts
5534
5539
  init_crypto();
@@ -5540,7 +5545,7 @@ var credentialsPasswordReset = ({
5540
5545
  passwordPolicy,
5541
5546
  resetPasswordRoute = "/auth/reset-password",
5542
5547
  resetTokenDurationMs = DEFAULT_RESET_TOKEN_TTL_MS
5543
- }) => new Elysia12().post(`${resetPasswordRoute}/request`, async ({ body: { email }, status }) => {
5548
+ }) => new Elysia12().post(`${resetPasswordRoute}/request`, { body: t9.Object({ email: t9.String() }) }, async ({ body: { email }, status }) => {
5544
5549
  const normalizedEmail = email.trim().toLowerCase();
5545
5550
  const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
5546
5551
  if (credential && credential.status === "active" && credential.registrationData === undefined) {
@@ -5559,7 +5564,9 @@ var credentialsPasswordReset = ({
5559
5564
  });
5560
5565
  }
5561
5566
  return status("OK", { status: "reset_requested" });
5562
- }, { body: t9.Object({ email: t9.String() }) }).post(resetPasswordRoute, async ({ body: { password, token }, status }) => {
5567
+ }).post(resetPasswordRoute, {
5568
+ body: t9.Object({ password: t9.String(), token: t9.String() })
5569
+ }, async ({ body: { password, token }, status }) => {
5563
5570
  const consumed = await credentialStore.consumeResetToken(await hashToken(token));
5564
5571
  if (!consumed) {
5565
5572
  return status("Bad Request", "Invalid or expired reset token");
@@ -5588,8 +5595,6 @@ var credentialsPasswordReset = ({
5588
5595
  });
5589
5596
  await onPasswordReset?.({ email: consumed.email });
5590
5597
  return status("OK", { status: "password_reset" });
5591
- }, {
5592
- body: t9.Object({ password: t9.String(), token: t9.String() })
5593
5598
  });
5594
5599
 
5595
5600
  // src/credentials/register.ts
@@ -5614,7 +5619,10 @@ var credentialsRegister = ({
5614
5619
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
5615
5620
  trustedOrigins,
5616
5621
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS
5617
- }) => new Elysia13().use(sessionStore()).post(registerRoute, async ({
5622
+ }) => new Elysia13().use(sessionStore()).post(registerRoute, {
5623
+ body: t10.Object({ email: t10.String(), password: t10.String() }, { additionalProperties: true }),
5624
+ cookie: t10.Cookie({ user_session_id: userSessionIdTypebox })
5625
+ }, async ({
5618
5626
  body: { email, password, ...extraFields },
5619
5627
  cookie: { user_session_id },
5620
5628
  request,
@@ -5712,10 +5720,7 @@ var credentialsRegister = ({
5712
5720
  userSessionId
5713
5721
  });
5714
5722
  return status("Created", { status: "authenticated" });
5715
- }), {
5716
- body: t10.Object({ email: t10.String(), password: t10.String() }, { additionalProperties: true }),
5717
- cookie: t10.Cookie({ user_session_id: userSessionIdTypebox })
5718
- });
5723
+ }));
5719
5724
 
5720
5725
  // src/credentials/routes.ts
5721
5726
  var credentialRoutes = (config) => new Elysia14().use(credentialsRegister(config)).use(credentialsEmailVerification(config)).use(credentialsLogin(config)).use(credentialsPasswordReset(config));
@@ -6189,7 +6194,10 @@ var mfaSmsRoutes = ({
6189
6194
  smsResendCooldownMs = DEFAULT_SMS_RESEND_COOLDOWN_MS,
6190
6195
  smsSetupRoute = "/auth/mfa/sms/setup",
6191
6196
  smsVerifyRoute = "/auth/mfa/sms/verify"
6192
- }) => new Elysia17().use(sessionStore()).post(smsSetupRoute, async ({
6197
+ }) => new Elysia17().use(sessionStore()).post(smsSetupRoute, {
6198
+ body: t11.Object({ phone: t11.String() }),
6199
+ cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
6200
+ }, async ({
6193
6201
  body: { phone },
6194
6202
  cookie: { user_session_id },
6195
6203
  status,
@@ -6250,10 +6258,10 @@ var mfaSmsRoutes = ({
6250
6258
  return status(mapped.status, mapped.message);
6251
6259
  }
6252
6260
  return status("OK", { phone: maskPhone(phone) });
6253
- }, {
6254
- body: t11.Object({ phone: t11.String() }),
6261
+ }).post(smsVerifyRoute, {
6262
+ body: t11.Object({ code: t11.String() }),
6255
6263
  cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
6256
- }).post(smsVerifyRoute, async ({
6264
+ }, async ({
6257
6265
  body: { code },
6258
6266
  cookie: { user_session_id },
6259
6267
  status,
@@ -6328,9 +6336,6 @@ var mfaSmsRoutes = ({
6328
6336
  }
6329
6337
  await onMfaEnrolled?.({ userId });
6330
6338
  return status("OK", { status: "enrolled" });
6331
- }, {
6332
- body: t11.Object({ code: t11.String() }),
6333
- cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
6334
6339
  });
6335
6340
 
6336
6341
  // src/mfa/challenge.ts
@@ -6352,7 +6357,14 @@ var mfaChallenge = ({
6352
6357
  smsMaxAttempts = DEFAULT_SMS_MAX_ATTEMPTS,
6353
6358
  smsResendCooldownMs = DEFAULT_SMS_RESEND_COOLDOWN_MS,
6354
6359
  totpMaxAttempts = DEFAULT_TOTP_MAX_ATTEMPTS
6355
- }) => new Elysia18().use(sessionStore()).post(challengeRoute, async ({
6360
+ }) => new Elysia18().use(sessionStore()).post(challengeRoute, {
6361
+ body: t12.Object({
6362
+ action: t12.Optional(t12.Union([t12.Literal("send"), t12.Literal("verify")])),
6363
+ code: t12.Optional(t12.String()),
6364
+ factor: t12.Optional(t12.Literal("sms"))
6365
+ }),
6366
+ cookie: t12.Cookie({ user_session_id: userSessionIdTypebox })
6367
+ }, async ({
6356
6368
  body: { action, code, factor },
6357
6369
  cookie: { user_session_id },
6358
6370
  status,
@@ -6525,14 +6537,7 @@ var mfaChallenge = ({
6525
6537
  updatedAt: Date.now()
6526
6538
  });
6527
6539
  return promote();
6528
- }), {
6529
- body: t12.Object({
6530
- action: t12.Optional(t12.Union([t12.Literal("send"), t12.Literal("verify")])),
6531
- code: t12.Optional(t12.String()),
6532
- factor: t12.Optional(t12.Literal("sms"))
6533
- }),
6534
- cookie: t12.Cookie({ user_session_id: userSessionIdTypebox })
6535
- });
6540
+ }));
6536
6541
 
6537
6542
  // src/mfa/management.ts
6538
6543
  import { Elysia as Elysia19, t as t13 } from "elysia";
@@ -6549,7 +6554,7 @@ var mfaManagementRoutes = ({
6549
6554
  managementRoute = "/auth/mfa",
6550
6555
  managementAuthMaxAgeMs = DEFAULT_MFA_MANAGEMENT_AUTH_MAX_AGE_MS,
6551
6556
  mfaStore
6552
- }) => new Elysia19().use(sessionStore()).get(managementRoute, async ({
6557
+ }) => new Elysia19().use(sessionStore()).get(managementRoute, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
6553
6558
  cookie: { user_session_id },
6554
6559
  status,
6555
6560
  store: { session }
@@ -6573,7 +6578,7 @@ var mfaManagementRoutes = ({
6573
6578
  totp: { enabled: enrollment?.totpVerified ?? false }
6574
6579
  };
6575
6580
  return status("OK", response);
6576
- }, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(managementRoute, async ({
6581
+ }).delete(managementRoute, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
6577
6582
  cookie: { user_session_id },
6578
6583
  status,
6579
6584
  store: { session }
@@ -6591,7 +6596,7 @@ var mfaManagementRoutes = ({
6591
6596
  }
6592
6597
  await mfaStore.removeEnrollment(getUserId(userSession.user));
6593
6598
  return status("OK", { status: "disabled" });
6594
- }, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) });
6599
+ });
6595
6600
 
6596
6601
  // src/mfa/totp.ts
6597
6602
  init_crypto();
@@ -6607,7 +6612,7 @@ var mfaTotpRoutes = ({
6607
6612
  onMfaEnrolled,
6608
6613
  totpSetupRoute = "/auth/mfa/totp/setup",
6609
6614
  totpVerifyRoute = "/auth/mfa/totp/verify"
6610
- }) => new Elysia20().use(sessionStore()).post(totpSetupRoute, async ({
6615
+ }) => new Elysia20().use(sessionStore()).post(totpSetupRoute, { cookie: t14.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
6611
6616
  cookie: { user_session_id },
6612
6617
  status,
6613
6618
  store: { session }
@@ -6648,7 +6653,10 @@ var mfaTotpRoutes = ({
6648
6653
  secret
6649
6654
  })
6650
6655
  });
6651
- }, { cookie: t14.Cookie({ user_session_id: userSessionIdTypebox }) }).post(totpVerifyRoute, async ({
6656
+ }).post(totpVerifyRoute, {
6657
+ body: t14.Object({ code: t14.String() }),
6658
+ cookie: t14.Cookie({ user_session_id: userSessionIdTypebox })
6659
+ }, async ({
6652
6660
  body: { code },
6653
6661
  cookie: { user_session_id },
6654
6662
  status,
@@ -6684,9 +6692,6 @@ var mfaTotpRoutes = ({
6684
6692
  });
6685
6693
  await onMfaEnrolled?.({ userId });
6686
6694
  return status("OK", { backupCodes: codes });
6687
- }, {
6688
- body: t14.Object({ code: t14.String() }),
6689
- cookie: t14.Cookie({ user_session_id: userSessionIdTypebox })
6690
6695
  });
6691
6696
 
6692
6697
  // src/mfa/routes.ts
@@ -7658,7 +7663,7 @@ var base64UrlEncode2 = (bytes) => {
7658
7663
  return btoa(binary).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
7659
7664
  };
7660
7665
  var computeCertThumbprint = async (derBytes) => {
7661
- const digest = await crypto.subtle.digest("SHA-256", derBytes);
7666
+ const digest = await crypto.subtle.digest("SHA-256", Uint8Array.from(derBytes));
7662
7667
  return base64UrlEncode2(new Uint8Array(digest));
7663
7668
  };
7664
7669
  var extractRfc9440ClientCert = (headers) => {
@@ -8752,7 +8757,30 @@ var oidcProviderRoutes = (config) => {
8752
8757
  url.searchParams.set("state", query.state);
8753
8758
  return redirectTo(url.toString());
8754
8759
  };
8755
- return new Elysia22().use(sessionStore()).get(authorizeRoute, async ({
8760
+ return new Elysia22().use(sessionStore()).get(authorizeRoute, {
8761
+ cookie: t15.Cookie({
8762
+ user_session_id: t15.Optional(userSessionIdTypebox)
8763
+ }),
8764
+ query: t15.Object({
8765
+ acr_values: t15.Optional(t15.String()),
8766
+ claims: t15.Optional(t15.String()),
8767
+ client_id: t15.Optional(t15.String()),
8768
+ code_challenge: t15.Optional(t15.String()),
8769
+ code_challenge_method: t15.Optional(t15.String()),
8770
+ id_token_hint: t15.Optional(t15.String()),
8771
+ max_age: t15.Optional(t15.String()),
8772
+ nonce: t15.Optional(t15.String()),
8773
+ prompt: t15.Optional(t15.String()),
8774
+ redirect_uri: t15.Optional(t15.String()),
8775
+ request: t15.Optional(t15.String()),
8776
+ request_uri: t15.Optional(t15.String()),
8777
+ resource: t15.Optional(t15.String()),
8778
+ response_mode: t15.Optional(t15.String()),
8779
+ response_type: t15.Optional(t15.String()),
8780
+ scope: t15.Optional(t15.String()),
8781
+ state: t15.Optional(t15.String())
8782
+ })
8783
+ }, async ({
8756
8784
  cookie: { user_session_id },
8757
8785
  query,
8758
8786
  request,
@@ -8838,7 +8866,7 @@ var oidcProviderRoutes = (config) => {
8838
8866
  const wantsSilent = promptValues.includes("none");
8839
8867
  const wantsLogin = promptValues.includes("login") || promptValues.includes("consent");
8840
8868
  const maxAge = effectiveQuery.max_age === undefined ? undefined : Number(effectiveQuery.max_age);
8841
- const sessionStaleByMaxAge = userSession !== undefined && maxAge !== undefined && !Number.isNaN(maxAge) && maxAge >= 0 && (userSession.authenticatedAt ?? 0) < Date.now() - maxAge * 1000;
8869
+ const sessionStaleByMaxAge = userSession !== undefined && maxAge !== undefined && !Number.isNaN(maxAge) && maxAge >= 0 && (maxAge === 0 || (userSession.authenticatedAt ?? 0) < Date.now() - maxAge * 1000);
8842
8870
  const hintSub = effectiveQuery.id_token_hint === undefined ? undefined : (await verifyIdTokenHint({
8843
8871
  config,
8844
8872
  idTokenHint: effectiveQuery.id_token_hint
@@ -8913,30 +8941,29 @@ var oidcProviderRoutes = (config) => {
8913
8941
  if (state !== undefined)
8914
8942
  params.state = state;
8915
8943
  return respondToClient(redirectUri, responseMode, params);
8916
- }, {
8917
- cookie: t15.Cookie({
8918
- user_session_id: t15.Optional(userSessionIdTypebox)
8919
- }),
8920
- query: t15.Object({
8921
- acr_values: t15.Optional(t15.String()),
8922
- claims: t15.Optional(t15.String()),
8944
+ }).post(tokenRoute, {
8945
+ body: t15.Object({
8946
+ assertion: t15.Optional(t15.String()),
8947
+ audience: t15.Optional(t15.String()),
8948
+ auth_req_id: t15.Optional(t15.String()),
8949
+ claim_token: t15.Optional(t15.String()),
8950
+ client_assertion: t15.Optional(t15.String()),
8951
+ client_assertion_type: t15.Optional(t15.String()),
8923
8952
  client_id: t15.Optional(t15.String()),
8924
- code_challenge: t15.Optional(t15.String()),
8925
- code_challenge_method: t15.Optional(t15.String()),
8926
- id_token_hint: t15.Optional(t15.String()),
8927
- max_age: t15.Optional(t15.String()),
8928
- nonce: t15.Optional(t15.String()),
8929
- prompt: t15.Optional(t15.String()),
8953
+ client_secret: t15.Optional(t15.String()),
8954
+ code: t15.Optional(t15.String()),
8955
+ code_verifier: t15.Optional(t15.String()),
8956
+ device_code: t15.Optional(t15.String()),
8957
+ grant_type: t15.Optional(t15.String()),
8958
+ "pre-authorized_code": t15.Optional(t15.String()),
8930
8959
  redirect_uri: t15.Optional(t15.String()),
8931
- request: t15.Optional(t15.String()),
8932
- request_uri: t15.Optional(t15.String()),
8960
+ refresh_token: t15.Optional(t15.String()),
8933
8961
  resource: t15.Optional(t15.String()),
8934
- response_mode: t15.Optional(t15.String()),
8935
- response_type: t15.Optional(t15.String()),
8936
8962
  scope: t15.Optional(t15.String()),
8937
- state: t15.Optional(t15.String())
8963
+ subject_token: t15.Optional(t15.String()),
8964
+ subject_token_type: t15.Optional(t15.String())
8938
8965
  })
8939
- }).post(tokenRoute, async ({ body, headers, request }) => {
8966
+ }, async ({ body, headers, request }) => {
8940
8967
  if (body.grant_type === PRE_AUTHORIZED_CODE_GRANT && config.vciConfig !== undefined) {
8941
8968
  const preAuthorizedCode = body["pre-authorized_code"];
8942
8969
  if (typeof preAuthorizedCode !== "string") {
@@ -9000,29 +9027,28 @@ var oidcProviderRoutes = (config) => {
9000
9027
  return grantBackchannel(client, body, headers.dpop, clientCertThumbprint);
9001
9028
  }
9002
9029
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
9003
- }, {
9030
+ }).post(parRoute, {
9004
9031
  body: t15.Object({
9005
- assertion: t15.Optional(t15.String()),
9032
+ acr_values: t15.Optional(t15.String()),
9006
9033
  audience: t15.Optional(t15.String()),
9007
- auth_req_id: t15.Optional(t15.String()),
9008
- claim_token: t15.Optional(t15.String()),
9034
+ claims: t15.Optional(t15.String()),
9009
9035
  client_assertion: t15.Optional(t15.String()),
9010
9036
  client_assertion_type: t15.Optional(t15.String()),
9011
9037
  client_id: t15.Optional(t15.String()),
9012
9038
  client_secret: t15.Optional(t15.String()),
9013
- code: t15.Optional(t15.String()),
9014
- code_verifier: t15.Optional(t15.String()),
9015
- device_code: t15.Optional(t15.String()),
9016
- grant_type: t15.Optional(t15.String()),
9017
- "pre-authorized_code": t15.Optional(t15.String()),
9039
+ code_challenge: t15.Optional(t15.String()),
9040
+ code_challenge_method: t15.Optional(t15.String()),
9041
+ nonce: t15.Optional(t15.String()),
9018
9042
  redirect_uri: t15.Optional(t15.String()),
9019
- refresh_token: t15.Optional(t15.String()),
9020
9043
  resource: t15.Optional(t15.String()),
9044
+ response_type: t15.Optional(t15.String()),
9021
9045
  scope: t15.Optional(t15.String()),
9022
- subject_token: t15.Optional(t15.String()),
9023
- subject_token_type: t15.Optional(t15.String())
9046
+ state: t15.Optional(t15.String())
9047
+ }),
9048
+ headers: t15.Object({
9049
+ authorization: t15.Optional(t15.String())
9024
9050
  })
9025
- }).post(parRoute, async ({ body, headers, request }) => {
9051
+ }, async ({ body, headers, request }) => {
9026
9052
  if (config.pushedAuthorizationRequestStore === undefined) {
9027
9053
  return oauthError2(HTTP_NOT_IMPLEMENTED, "unsupported_response_type");
9028
9054
  }
@@ -9049,28 +9075,17 @@ var oidcProviderRoutes = (config) => {
9049
9075
  ttlMs: config.pushedAuthorizationRequestTtlMs
9050
9076
  });
9051
9077
  return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
9052
- }, {
9078
+ }).post(introspectRoute, {
9053
9079
  body: t15.Object({
9054
- acr_values: t15.Optional(t15.String()),
9055
- audience: t15.Optional(t15.String()),
9056
- claims: t15.Optional(t15.String()),
9057
- client_assertion: t15.Optional(t15.String()),
9058
- client_assertion_type: t15.Optional(t15.String()),
9059
9080
  client_id: t15.Optional(t15.String()),
9060
9081
  client_secret: t15.Optional(t15.String()),
9061
- code_challenge: t15.Optional(t15.String()),
9062
- code_challenge_method: t15.Optional(t15.String()),
9063
- nonce: t15.Optional(t15.String()),
9064
- redirect_uri: t15.Optional(t15.String()),
9065
- resource: t15.Optional(t15.String()),
9066
- response_type: t15.Optional(t15.String()),
9067
- scope: t15.Optional(t15.String()),
9068
- state: t15.Optional(t15.String())
9082
+ token: t15.String(),
9083
+ token_type_hint: t15.Optional(t15.String())
9069
9084
  }),
9070
9085
  headers: t15.Object({
9071
9086
  authorization: t15.Optional(t15.String())
9072
9087
  })
9073
- }).post(introspectRoute, async ({ body, headers }) => {
9088
+ }, async ({ body, headers }) => {
9074
9089
  const basic = readBasicAuth2(headers.authorization);
9075
9090
  const clientId = body.client_id ?? basic.clientId;
9076
9091
  const clientSecret = body.client_secret ?? basic.clientSecret;
@@ -9088,7 +9103,7 @@ var oidcProviderRoutes = (config) => {
9088
9103
  token: body.token
9089
9104
  });
9090
9105
  return jsonResponse(result, HTTP_OK3);
9091
- }, {
9106
+ }).post(revokeRoute, {
9092
9107
  body: t15.Object({
9093
9108
  client_id: t15.Optional(t15.String()),
9094
9109
  client_secret: t15.Optional(t15.String()),
@@ -9098,7 +9113,7 @@ var oidcProviderRoutes = (config) => {
9098
9113
  headers: t15.Object({
9099
9114
  authorization: t15.Optional(t15.String())
9100
9115
  })
9101
- }).post(revokeRoute, async ({ body, headers }) => {
9116
+ }, async ({ body, headers }) => {
9102
9117
  const basic = readBasicAuth2(headers.authorization);
9103
9118
  const clientId = body.client_id ?? basic.clientId;
9104
9119
  const clientSecret = body.client_secret ?? basic.clientSecret;
@@ -9113,17 +9128,18 @@ var oidcProviderRoutes = (config) => {
9113
9128
  await revokeRefreshToken(config, body.token);
9114
9129
  }
9115
9130
  return new Response(null, { status: HTTP_OK3 });
9116
- }, {
9131
+ }).post(backchannelAuthorizationRoute, {
9117
9132
  body: t15.Object({
9133
+ binding_message: t15.Optional(t15.String()),
9118
9134
  client_id: t15.Optional(t15.String()),
9119
9135
  client_secret: t15.Optional(t15.String()),
9120
- token: t15.String(),
9121
- token_type_hint: t15.Optional(t15.String())
9136
+ login_hint: t15.Optional(t15.String()),
9137
+ scope: t15.Optional(t15.String())
9122
9138
  }),
9123
9139
  headers: t15.Object({
9124
9140
  authorization: t15.Optional(t15.String())
9125
9141
  })
9126
- }).post(backchannelAuthorizationRoute, async ({ body, headers }) => {
9142
+ }, async ({ body, headers }) => {
9127
9143
  if (config.backchannelAuthStore === undefined) {
9128
9144
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
9129
9145
  }
@@ -9156,18 +9172,16 @@ var oidcProviderRoutes = (config) => {
9156
9172
  expires_in: result.expires_in,
9157
9173
  interval: result.interval
9158
9174
  }, HTTP_OK3);
9159
- }, {
9175
+ }).post(deviceAuthorizationRoute, {
9160
9176
  body: t15.Object({
9161
- binding_message: t15.Optional(t15.String()),
9162
9177
  client_id: t15.Optional(t15.String()),
9163
9178
  client_secret: t15.Optional(t15.String()),
9164
- login_hint: t15.Optional(t15.String()),
9165
9179
  scope: t15.Optional(t15.String())
9166
9180
  }),
9167
9181
  headers: t15.Object({
9168
9182
  authorization: t15.Optional(t15.String())
9169
9183
  })
9170
- }).post(deviceAuthorizationRoute, async ({ body, headers }) => {
9184
+ }, async ({ body, headers }) => {
9171
9185
  if (config.deviceAuthorizationStore === undefined) {
9172
9186
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
9173
9187
  }
@@ -9189,16 +9203,15 @@ var oidcProviderRoutes = (config) => {
9189
9203
  requestedScopes: requested
9190
9204
  });
9191
9205
  return jsonResponse(response, HTTP_OK3);
9192
- }, {
9206
+ }).post(deviceApproveRoute, {
9193
9207
  body: t15.Object({
9194
- client_id: t15.Optional(t15.String()),
9195
- client_secret: t15.Optional(t15.String()),
9196
- scope: t15.Optional(t15.String())
9208
+ action: t15.Optional(t15.Union([t15.Literal("approve"), t15.Literal("deny")])),
9209
+ user_code: t15.String()
9197
9210
  }),
9198
- headers: t15.Object({
9199
- authorization: t15.Optional(t15.String())
9211
+ cookie: t15.Cookie({
9212
+ user_session_id: t15.Optional(userSessionIdTypebox)
9200
9213
  })
9201
- }).post(deviceApproveRoute, async ({ body, cookie: { user_session_id }, store }) => {
9214
+ }, async ({ body, cookie: { user_session_id }, store }) => {
9202
9215
  if (config.deviceAuthorizationStore === undefined) {
9203
9216
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
9204
9217
  }
@@ -9221,19 +9234,7 @@ var oidcProviderRoutes = (config) => {
9221
9234
  if (!result.ok)
9222
9235
  return oauthError2(HTTP_BAD_REQUEST3, result.error);
9223
9236
  return jsonResponse({ ok: true }, HTTP_OK3);
9224
- }, {
9225
- body: t15.Object({
9226
- action: t15.Optional(t15.Union([t15.Literal("approve"), t15.Literal("deny")])),
9227
- user_code: t15.String()
9228
- }),
9229
- cookie: t15.Cookie({
9230
- user_session_id: t15.Optional(userSessionIdTypebox)
9231
- })
9232
- }).get(endSessionRoute, async ({ cookie: { user_session_id }, query, store }) => handleEndSession({
9233
- cookie: user_session_id,
9234
- inMemorySession: store.session,
9235
- query
9236
- }), {
9237
+ }).get(endSessionRoute, {
9237
9238
  cookie: t15.Cookie({
9238
9239
  user_session_id: t15.Optional(userSessionIdTypebox)
9239
9240
  }),
@@ -9243,11 +9244,11 @@ var oidcProviderRoutes = (config) => {
9243
9244
  post_logout_redirect_uri: t15.Optional(t15.String()),
9244
9245
  state: t15.Optional(t15.String())
9245
9246
  })
9246
- }).post(endSessionRoute, async ({ body, cookie: { user_session_id }, store }) => handleEndSession({
9247
+ }, async ({ cookie: { user_session_id }, query, store }) => handleEndSession({
9247
9248
  cookie: user_session_id,
9248
9249
  inMemorySession: store.session,
9249
- query: body
9250
- }), {
9250
+ query
9251
+ })).post(endSessionRoute, {
9251
9252
  body: t15.Object({
9252
9253
  client_id: t15.Optional(t15.String()),
9253
9254
  id_token_hint: t15.Optional(t15.String()),
@@ -9257,7 +9258,25 @@ var oidcProviderRoutes = (config) => {
9257
9258
  cookie: t15.Cookie({
9258
9259
  user_session_id: t15.Optional(userSessionIdTypebox)
9259
9260
  })
9260
- }).post(registrationRoute, async ({ body, headers }) => {
9261
+ }, async ({ body, cookie: { user_session_id }, store }) => handleEndSession({
9262
+ cookie: user_session_id,
9263
+ inMemorySession: store.session,
9264
+ query: body
9265
+ })).post(registrationRoute, {
9266
+ body: t15.Object({
9267
+ backchannel_logout_uri: t15.Optional(t15.String()),
9268
+ client_name: t15.Optional(t15.String()),
9269
+ grant_types: t15.Optional(t15.Array(t15.String())),
9270
+ jwks: t15.Optional(t15.Any()),
9271
+ jwks_uri: t15.Optional(t15.String()),
9272
+ post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
9273
+ redirect_uris: t15.Optional(t15.Array(t15.String())),
9274
+ scope: t15.Optional(t15.String())
9275
+ }),
9276
+ headers: t15.Object({
9277
+ authorization: t15.Optional(t15.String())
9278
+ })
9279
+ }, async ({ body, headers }) => {
9261
9280
  if (config.clientRegistrationTokenStore === undefined) {
9262
9281
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
9263
9282
  }
@@ -9273,21 +9292,12 @@ var oidcProviderRoutes = (config) => {
9273
9292
  registrationTokenStore: config.clientRegistrationTokenStore
9274
9293
  });
9275
9294
  return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
9276
- }, {
9277
- body: t15.Object({
9278
- backchannel_logout_uri: t15.Optional(t15.String()),
9279
- client_name: t15.Optional(t15.String()),
9280
- grant_types: t15.Optional(t15.Array(t15.String())),
9281
- jwks: t15.Optional(t15.Any()),
9282
- jwks_uri: t15.Optional(t15.String()),
9283
- post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
9284
- redirect_uris: t15.Optional(t15.Array(t15.String())),
9285
- scope: t15.Optional(t15.String())
9286
- }),
9295
+ }).get(`${registrationRoute}/:clientId`, {
9287
9296
  headers: t15.Object({
9288
9297
  authorization: t15.Optional(t15.String())
9289
- })
9290
- }).get(`${registrationRoute}/:clientId`, async ({ headers, params: { clientId } }) => {
9298
+ }),
9299
+ params: t15.Object({ clientId: t15.String() })
9300
+ }, async ({ headers, params: { clientId } }) => {
9291
9301
  if (config.clientRegistrationTokenStore === undefined) {
9292
9302
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
9293
9303
  }
@@ -9298,12 +9308,22 @@ var oidcProviderRoutes = (config) => {
9298
9308
  registrationTokenStore: config.clientRegistrationTokenStore
9299
9309
  });
9300
9310
  return jsonResponse(result.body, result.status);
9301
- }, {
9311
+ }).put(`${registrationRoute}/:clientId`, {
9312
+ body: t15.Object({
9313
+ backchannel_logout_uri: t15.Optional(t15.String()),
9314
+ client_name: t15.Optional(t15.String()),
9315
+ grant_types: t15.Optional(t15.Array(t15.String())),
9316
+ jwks: t15.Optional(t15.Any()),
9317
+ jwks_uri: t15.Optional(t15.String()),
9318
+ post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
9319
+ redirect_uris: t15.Optional(t15.Array(t15.String())),
9320
+ scope: t15.Optional(t15.String())
9321
+ }),
9302
9322
  headers: t15.Object({
9303
9323
  authorization: t15.Optional(t15.String())
9304
9324
  }),
9305
9325
  params: t15.Object({ clientId: t15.String() })
9306
- }).put(`${registrationRoute}/:clientId`, async ({ body, headers, params: { clientId } }) => {
9326
+ }, async ({ body, headers, params: { clientId } }) => {
9307
9327
  if (config.clientRegistrationTokenStore === undefined) {
9308
9328
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
9309
9329
  }
@@ -9316,22 +9336,12 @@ var oidcProviderRoutes = (config) => {
9316
9336
  registrationTokenStore: config.clientRegistrationTokenStore
9317
9337
  });
9318
9338
  return jsonResponse(result.body, result.status);
9319
- }, {
9320
- body: t15.Object({
9321
- backchannel_logout_uri: t15.Optional(t15.String()),
9322
- client_name: t15.Optional(t15.String()),
9323
- grant_types: t15.Optional(t15.Array(t15.String())),
9324
- jwks: t15.Optional(t15.Any()),
9325
- jwks_uri: t15.Optional(t15.String()),
9326
- post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
9327
- redirect_uris: t15.Optional(t15.Array(t15.String())),
9328
- scope: t15.Optional(t15.String())
9329
- }),
9339
+ }).delete(`${registrationRoute}/:clientId`, {
9330
9340
  headers: t15.Object({
9331
9341
  authorization: t15.Optional(t15.String())
9332
9342
  }),
9333
9343
  params: t15.Object({ clientId: t15.String() })
9334
- }).delete(`${registrationRoute}/:clientId`, async ({ headers, params: { clientId } }) => {
9344
+ }, async ({ headers, params: { clientId } }) => {
9335
9345
  if (config.clientRegistrationTokenStore === undefined) {
9336
9346
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
9337
9347
  }
@@ -9345,12 +9355,11 @@ var oidcProviderRoutes = (config) => {
9345
9355
  return new Response(null, { status: HTTP_NO_CONTENT });
9346
9356
  }
9347
9357
  return jsonResponse(result.body, result.status);
9348
- }, {
9358
+ }).get(userinfoRoute, {
9349
9359
  headers: t15.Object({
9350
9360
  authorization: t15.Optional(t15.String())
9351
- }),
9352
- params: t15.Object({ clientId: t15.String() })
9353
- }).get(userinfoRoute, async ({ headers }) => {
9361
+ })
9362
+ }, async ({ headers }) => {
9354
9363
  const token = readUserInfoBearer(headers.authorization);
9355
9364
  const result = await fetchUserInfo({ config, token });
9356
9365
  if (!result.ok) {
@@ -9363,11 +9372,14 @@ var oidcProviderRoutes = (config) => {
9363
9372
  });
9364
9373
  }
9365
9374
  return jsonResponse(result.body, HTTP_OK3);
9366
- }, {
9375
+ }).post(userinfoRoute, {
9376
+ body: t15.Object({
9377
+ access_token: t15.Optional(t15.String())
9378
+ }),
9367
9379
  headers: t15.Object({
9368
9380
  authorization: t15.Optional(t15.String())
9369
9381
  })
9370
- }).post(userinfoRoute, async ({ headers, body }) => {
9382
+ }, async ({ headers, body }) => {
9371
9383
  const token = readUserInfoBearer(headers.authorization) ?? body.access_token;
9372
9384
  const result = await fetchUserInfo({ config, token });
9373
9385
  if (!result.ok) {
@@ -9380,13 +9392,6 @@ var oidcProviderRoutes = (config) => {
9380
9392
  });
9381
9393
  }
9382
9394
  return jsonResponse(result.body, HTTP_OK3);
9383
- }, {
9384
- body: t15.Object({
9385
- access_token: t15.Optional(t15.String())
9386
- }),
9387
- headers: t15.Object({
9388
- authorization: t15.Optional(t15.String())
9389
- })
9390
9395
  }).get(jwksRoute, () => ({
9391
9396
  keys: signingVerificationKeys(signingKey, config.previousSigningKeys).map(toPublicJwk)
9392
9397
  })).get("/.well-known/openid-configuration", () => discovery).get("/.well-known/oauth-authorization-server", () => discovery);
@@ -9525,7 +9530,7 @@ var organizationRoutes = ({
9525
9530
  }
9526
9531
  return membership?.status === "active";
9527
9532
  };
9528
- return new Elysia23().use(sessionStore()).get(organizationsRoute, async ({
9533
+ return new Elysia23().use(sessionStore()).get(organizationsRoute, { cookie }, async ({
9529
9534
  cookie: { user_session_id },
9530
9535
  status,
9531
9536
  store: { session }
@@ -9539,7 +9544,13 @@ var organizationRoutes = ({
9539
9544
  userId: getUserId(user)
9540
9545
  });
9541
9546
  return status("OK", { organizations });
9542
- }, { cookie }).post(organizationsRoute, async ({
9547
+ }).post(organizationsRoute, {
9548
+ body: t16.Object({
9549
+ metadata: t16.Optional(t16.Record(t16.String(), t16.Unknown())),
9550
+ name: t16.String()
9551
+ }),
9552
+ cookie
9553
+ }, async ({
9543
9554
  body: { metadata, name },
9544
9555
  cookie: { user_session_id },
9545
9556
  status,
@@ -9571,13 +9582,14 @@ var organizationRoutes = ({
9571
9582
  ownerUserId
9572
9583
  });
9573
9584
  return status("OK", { organization });
9574
- }, {
9585
+ }).post(`${organizationsRoute}/:organizationId/invitations`, {
9575
9586
  body: t16.Object({
9576
- metadata: t16.Optional(t16.Record(t16.String(), t16.Unknown())),
9577
- name: t16.String()
9587
+ email: t16.String(),
9588
+ roles: t16.Optional(t16.Array(t16.String()))
9578
9589
  }),
9579
- cookie
9580
- }).post(`${organizationsRoute}/:organizationId/invitations`, async ({
9590
+ cookie,
9591
+ params: t16.Object({ organizationId: t16.String() })
9592
+ }, async ({
9581
9593
  body: { email, roles },
9582
9594
  cookie: { user_session_id },
9583
9595
  params: { organizationId },
@@ -9617,14 +9629,7 @@ var organizationRoutes = ({
9617
9629
  invitationId: invitation.invitationId,
9618
9630
  token
9619
9631
  });
9620
- }, {
9621
- body: t16.Object({
9622
- email: t16.String(),
9623
- roles: t16.Optional(t16.Array(t16.String()))
9624
- }),
9625
- cookie,
9626
- params: t16.Object({ organizationId: t16.String() })
9627
- }).get(`${organizationsRoute}/:organizationId/invitations`, async ({
9632
+ }).get(`${organizationsRoute}/:organizationId/invitations`, { cookie, params: t16.Object({ organizationId: t16.String() }) }, async ({
9628
9633
  cookie: { user_session_id },
9629
9634
  params: { organizationId },
9630
9635
  status,
@@ -9647,7 +9652,13 @@ var organizationRoutes = ({
9647
9652
  state: invitation.state
9648
9653
  }))
9649
9654
  });
9650
- }, { cookie, params: t16.Object({ organizationId: t16.String() }) }).delete(`${organizationsRoute}/:organizationId/invitations/:invitationId`, async ({
9655
+ }).delete(`${organizationsRoute}/:organizationId/invitations/:invitationId`, {
9656
+ cookie,
9657
+ params: t16.Object({
9658
+ invitationId: t16.String(),
9659
+ organizationId: t16.String()
9660
+ })
9661
+ }, async ({
9651
9662
  cookie: { user_session_id },
9652
9663
  params: { invitationId, organizationId },
9653
9664
  status,
@@ -9669,13 +9680,7 @@ var organizationRoutes = ({
9669
9680
  state: "revoked"
9670
9681
  });
9671
9682
  return status("OK", { revoked: invitationId });
9672
- }, {
9673
- cookie,
9674
- params: t16.Object({
9675
- invitationId: t16.String(),
9676
- organizationId: t16.String()
9677
- })
9678
- }).post(`${organizationsRoute}/invitations/accept`, async ({
9683
+ }).post(`${organizationsRoute}/invitations/accept`, { body: t16.Object({ token: t16.String() }), cookie }, async ({
9679
9684
  body: { token },
9680
9685
  cookie: { user_session_id },
9681
9686
  status,
@@ -9708,7 +9713,7 @@ var organizationRoutes = ({
9708
9713
  organizationId: membership.organizationId,
9709
9714
  roles: membership.roles
9710
9715
  });
9711
- }, { body: t16.Object({ token: t16.String() }), cookie }).get(`${organizationsRoute}/:organizationId/members`, async ({
9716
+ }).get(`${organizationsRoute}/:organizationId/members`, { cookie, params: t16.Object({ organizationId: t16.String() }) }, async ({
9712
9717
  cookie: { user_session_id },
9713
9718
  params: { organizationId },
9714
9719
  status,
@@ -9724,7 +9729,13 @@ var organizationRoutes = ({
9724
9729
  }
9725
9730
  const members = await organizationStore.listMembershipsByOrganization(organizationId);
9726
9731
  return status("OK", { members });
9727
- }, { cookie, params: t16.Object({ organizationId: t16.String() }) }).delete(`${organizationsRoute}/:organizationId/members/:userId`, async ({
9732
+ }).delete(`${organizationsRoute}/:organizationId/members/:userId`, {
9733
+ cookie,
9734
+ params: t16.Object({
9735
+ organizationId: t16.String(),
9736
+ userId: t16.String()
9737
+ })
9738
+ }, async ({
9728
9739
  cookie: { user_session_id },
9729
9740
  params: { organizationId, userId },
9730
9741
  status,
@@ -9746,12 +9757,6 @@ var organizationRoutes = ({
9746
9757
  });
9747
9758
  await onMembershipRemoved?.({ organizationId, userId });
9748
9759
  return status("OK", { removed: userId });
9749
- }, {
9750
- cookie,
9751
- params: t16.Object({
9752
- organizationId: t16.String(),
9753
- userId: t16.String()
9754
- })
9755
9760
  });
9756
9761
  };
9757
9762
 
@@ -9818,7 +9823,7 @@ var passwordlessRoutes = ({
9818
9823
  await onPasswordlessLogin?.({ user, userSessionId });
9819
9824
  return userSessionId;
9820
9825
  };
9821
- const magicLink = onSendMagicLink ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, async ({ body: { email }, status }) => {
9826
+ const magicLink = onSendMagicLink ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, { body: t17.Object({ email: t17.String() }) }, async ({ body: { email }, status }) => {
9822
9827
  const normalizedEmail = email.trim().toLowerCase();
9823
9828
  const token = generateSecureToken();
9824
9829
  const expiresAt = Date.now() + magicLinkTokenDurationMs;
@@ -9833,7 +9838,7 @@ var passwordlessRoutes = ({
9833
9838
  token
9834
9839
  });
9835
9840
  return status("OK", { status: "magic_link_sent" });
9836
- }, { body: t17.Object({ email: t17.String() }) }).post(`${passwordlessRoute}/magic-link/verify`, async ({
9841
+ }).post(`${passwordlessRoute}/magic-link/verify`, { body: t17.Object({ token: t17.String() }), cookie }, async ({
9837
9842
  body: { token },
9838
9843
  cookie: { user_session_id },
9839
9844
  status,
@@ -9848,8 +9853,8 @@ var passwordlessRoutes = ({
9848
9853
  return status("Unauthorized", "No account for this email");
9849
9854
  }
9850
9855
  return status("OK", { status: "authenticated" });
9851
- }, { body: t17.Object({ token: t17.String() }), cookie }) : new Elysia24;
9852
- const otp = onSendOtp ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/otp`, async ({ body: { email }, status }) => {
9856
+ }) : new Elysia24;
9857
+ const otp = onSendOtp ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/otp`, { body: t17.Object({ email: t17.String() }) }, async ({ body: { email }, status }) => {
9853
9858
  const normalizedEmail = email.trim().toLowerCase();
9854
9859
  const code = generateOtpCode(otpLength);
9855
9860
  const expiresAt = Date.now() + otpDurationMs;
@@ -9864,7 +9869,13 @@ var passwordlessRoutes = ({
9864
9869
  expiresAt
9865
9870
  });
9866
9871
  return status("OK", { status: "otp_sent" });
9867
- }, { body: t17.Object({ email: t17.String() }) }).post(`${passwordlessRoute}/otp/verify`, async ({
9872
+ }).post(`${passwordlessRoute}/otp/verify`, {
9873
+ body: t17.Object({
9874
+ code: t17.String(),
9875
+ email: t17.String()
9876
+ }),
9877
+ cookie
9878
+ }, async ({
9868
9879
  body: { code, email },
9869
9880
  cookie: { user_session_id },
9870
9881
  status,
@@ -9880,12 +9891,6 @@ var passwordlessRoutes = ({
9880
9891
  return status("Unauthorized", "No account for this email");
9881
9892
  }
9882
9893
  return status("OK", { status: "authenticated" });
9883
- }, {
9884
- body: t17.Object({
9885
- code: t17.String(),
9886
- email: t17.String()
9887
- }),
9888
- cookie
9889
9894
  }) : new Elysia24;
9890
9895
  return new Elysia24().use(magicLink).use(otp);
9891
9896
  };
@@ -10009,7 +10014,14 @@ var portalRoutes = ({
10009
10014
  } : undefined,
10010
10015
  scim: capabilities.includes("scim") ? { baseUrl: `${origin}${scimRoute}` } : undefined
10011
10016
  });
10012
- }).put(`${portalRoute}/connection/saml`, async ({ body, headers, status }) => {
10017
+ }).put(`${portalRoute}/connection/saml`, {
10018
+ body: t18.Object({
10019
+ idpEntityId: t18.String(),
10020
+ idpSloUrl: t18.Optional(t18.String()),
10021
+ idpSsoUrl: t18.String(),
10022
+ idpX509Cert: t18.String()
10023
+ })
10024
+ }, async ({ body, headers, status }) => {
10013
10025
  const session = await loadSession(headers.authorization);
10014
10026
  if (!session) {
10015
10027
  return status("Unauthorized", "Invalid or expired setup link");
@@ -10048,14 +10060,15 @@ var portalRoutes = ({
10048
10060
  type: "saml"
10049
10061
  });
10050
10062
  return status("OK", { configured: true, type: "saml" });
10051
- }, {
10063
+ }).put(`${portalRoute}/connection/oidc`, {
10052
10064
  body: t18.Object({
10053
- idpEntityId: t18.String(),
10054
- idpSloUrl: t18.Optional(t18.String()),
10055
- idpSsoUrl: t18.String(),
10056
- idpX509Cert: t18.String()
10065
+ clientId: t18.String(),
10066
+ clientSecret: t18.String(),
10067
+ issuer: t18.String(),
10068
+ redirectUri: t18.Optional(t18.String()),
10069
+ scopes: t18.Optional(t18.Array(t18.String()))
10057
10070
  })
10058
- }).put(`${portalRoute}/connection/oidc`, async ({ body, headers, request, status }) => {
10071
+ }, async ({ body, headers, request, status }) => {
10059
10072
  const session = await loadSession(headers.authorization);
10060
10073
  if (!session) {
10061
10074
  return status("Unauthorized", "Invalid or expired setup link");
@@ -10096,14 +10109,6 @@ var portalRoutes = ({
10096
10109
  type: "oidc"
10097
10110
  });
10098
10111
  return status("OK", { configured: true, type: "oidc" });
10099
- }, {
10100
- body: t18.Object({
10101
- clientId: t18.String(),
10102
- clientSecret: t18.String(),
10103
- issuer: t18.String(),
10104
- redirectUri: t18.Optional(t18.String()),
10105
- scopes: t18.Optional(t18.Array(t18.String()))
10106
- })
10107
10112
  }).post(`${portalRoute}/scim/token`, async ({ headers, request, status }) => {
10108
10113
  const session = await loadSession(headers.authorization);
10109
10114
  if (!session) {
@@ -10184,7 +10189,7 @@ var roleRoutes = ({
10184
10189
  }
10185
10190
  return membership?.status === "active";
10186
10191
  };
10187
- return new Elysia26().use(sessionStore()).get(`${rolesRoute}/:organizationId`, async ({
10192
+ return new Elysia26().use(sessionStore()).get(`${rolesRoute}/:organizationId`, { cookie, params: t19.Object({ organizationId: t19.String() }) }, async ({
10188
10193
  cookie: { user_session_id },
10189
10194
  params: { organizationId },
10190
10195
  status,
@@ -10202,7 +10207,14 @@ var roleRoutes = ({
10202
10207
  roleStore.listRoles()
10203
10208
  ]);
10204
10209
  return status("OK", { roles: [...scoped, ...global] });
10205
- }, { cookie, params: t19.Object({ organizationId: t19.String() }) }).put(`${rolesRoute}/:organizationId/members/:userId`, async ({
10210
+ }).put(`${rolesRoute}/:organizationId/members/:userId`, {
10211
+ body: t19.Object({ roles: t19.Array(t19.String()) }),
10212
+ cookie,
10213
+ params: t19.Object({
10214
+ organizationId: t19.String(),
10215
+ userId: t19.String()
10216
+ })
10217
+ }, async ({
10206
10218
  body: { roles },
10207
10219
  cookie: { user_session_id },
10208
10220
  params: { organizationId, userId },
@@ -10234,13 +10246,6 @@ var roleRoutes = ({
10234
10246
  });
10235
10247
  await onRolesAssigned?.({ organizationId, roles, userId });
10236
10248
  return status("OK", { roles: updated.roles });
10237
- }, {
10238
- body: t19.Object({ roles: t19.Array(t19.String()) }),
10239
- cookie,
10240
- params: t19.Object({
10241
- organizationId: t19.String(),
10242
- userId: t19.String()
10243
- })
10244
10249
  });
10245
10250
  };
10246
10251
 
@@ -10432,7 +10437,20 @@ var authorize = ({
10432
10437
  onAuthorizeError
10433
10438
  }) => {
10434
10439
  const secure = resolveCookieSecure(cookieSecure);
10435
- return new Elysia27().get(authorizeRoute, async ({
10440
+ return new Elysia27().get(authorizeRoute, {
10441
+ cookie: t20.Cookie({
10442
+ auth_client: authClientOption,
10443
+ auth_intent: authIntentOption,
10444
+ auth_provider: t20.Optional(authProviderOption)
10445
+ }),
10446
+ params: t20.Object({
10447
+ provider: authProviderOption
10448
+ }),
10449
+ query: t20.Object({
10450
+ client: authClientOption,
10451
+ intent: authIntentOption
10452
+ })
10453
+ }, async ({
10436
10454
  status,
10437
10455
  redirect,
10438
10456
  cookie: {
@@ -10548,19 +10566,6 @@ var authorize = ({
10548
10566
  });
10549
10567
  return status("Internal Server Error", "Failed to create authorization URL");
10550
10568
  }
10551
- }, {
10552
- cookie: t20.Cookie({
10553
- auth_client: authClientOption,
10554
- auth_intent: authIntentOption,
10555
- auth_provider: t20.Optional(authProviderOption)
10556
- }),
10557
- params: t20.Object({
10558
- provider: authProviderOption
10559
- }),
10560
- query: t20.Object({
10561
- client: authClientOption,
10562
- intent: authIntentOption
10563
- })
10564
10569
  });
10565
10570
  };
10566
10571
 
@@ -10588,7 +10593,17 @@ var callback = ({
10588
10593
  onLinkIdentityConflict,
10589
10594
  onLinkConnector,
10590
10595
  onCallbackError
10591
- }) => new Elysia28().use(sessionStore()).get(callbackRoute, async ({
10596
+ }) => new Elysia28().use(sessionStore()).get(callbackRoute, {
10597
+ cookie: t21.Cookie({
10598
+ auth_client: authClientOption,
10599
+ auth_intent: authIntentOption,
10600
+ auth_provider: t21.Optional(authProviderOption),
10601
+ code_verifier: t21.Optional(t21.String()),
10602
+ origin_url: t21.Optional(t21.String()),
10603
+ state: t21.Optional(t21.String()),
10604
+ user_session_id: t21.Optional(userSessionIdTypebox)
10605
+ })
10606
+ }, async ({
10592
10607
  status,
10593
10608
  redirect,
10594
10609
  store: { session, unregisteredSession },
@@ -10722,17 +10737,7 @@ var callback = ({
10722
10737
  return response;
10723
10738
  }
10724
10739
  return redirect(originUrl);
10725
- }), {
10726
- cookie: t21.Cookie({
10727
- auth_client: authClientOption,
10728
- auth_intent: authIntentOption,
10729
- auth_provider: t21.Optional(authProviderOption),
10730
- code_verifier: t21.Optional(t21.String()),
10731
- origin_url: t21.Optional(t21.String()),
10732
- state: t21.Optional(t21.String()),
10733
- user_session_id: t21.Optional(userSessionIdTypebox)
10734
- })
10735
- });
10740
+ }));
10736
10741
 
10737
10742
  // src/routes/profile.ts
10738
10743
  import { Elysia as Elysia29, t as t22 } from "elysia";
@@ -10742,7 +10747,13 @@ var profile = ({
10742
10747
  profileRoute = "/oauth2/profile",
10743
10748
  onProfileSuccess,
10744
10749
  onProfileError
10745
- }) => new Elysia29().use(sessionStore()).get(profileRoute, async ({
10750
+ }) => new Elysia29().use(sessionStore()).get(profileRoute, {
10751
+ cookie: t22.Cookie({
10752
+ auth_client: authClientOption,
10753
+ auth_provider: authProviderOption,
10754
+ user_session_id: userSessionIdTypebox
10755
+ })
10756
+ }, async ({
10746
10757
  status,
10747
10758
  store: { session },
10748
10759
  cookie: { user_session_id, auth_provider, auth_client }
@@ -10795,12 +10806,6 @@ var profile = ({
10795
10806
  });
10796
10807
  return err instanceof Error ? status("Internal Server Error", `${err.message} - ${err.stack ?? ""}`) : status("Internal Server Error", `Failed to validate authorization code: Unknown status: ${err}`);
10797
10808
  }
10798
- }, {
10799
- cookie: t22.Cookie({
10800
- auth_client: authClientOption,
10801
- auth_provider: authProviderOption,
10802
- user_session_id: userSessionIdTypebox
10803
- })
10804
10809
  });
10805
10810
 
10806
10811
  // src/routes/refresh.ts
@@ -10813,7 +10818,13 @@ var refresh = ({
10813
10818
  onRefreshSuccess,
10814
10819
  onRefreshError,
10815
10820
  sessionDurationMs = MILLISECONDS_IN_A_DAY
10816
- }) => new Elysia30().use(sessionStore()).post(refreshRoute, async ({
10821
+ }) => new Elysia30().use(sessionStore()).post(refreshRoute, {
10822
+ cookie: t23.Cookie({
10823
+ auth_client: authClientOption,
10824
+ auth_provider: authProviderOption,
10825
+ user_session_id: userSessionIdTypebox
10826
+ })
10827
+ }, async ({
10817
10828
  status,
10818
10829
  store: { session },
10819
10830
  cookie: { user_session_id, auth_provider, auth_client }
@@ -10878,12 +10889,6 @@ var refresh = ({
10878
10889
  });
10879
10890
  return status("Internal Server Error", "Failed to refresh token");
10880
10891
  }
10881
- }, {
10882
- cookie: t23.Cookie({
10883
- auth_client: authClientOption,
10884
- auth_provider: authProviderOption,
10885
- user_session_id: userSessionIdTypebox
10886
- })
10887
10892
  });
10888
10893
 
10889
10894
  // src/routes/revoke.ts
@@ -10894,7 +10899,13 @@ var revoke = ({
10894
10899
  revokeRoute = "/oauth2/revocation",
10895
10900
  onRevocationSuccess,
10896
10901
  onRevocationError
10897
- }) => new Elysia31().use(sessionStore()).post(revokeRoute, async ({
10902
+ }) => new Elysia31().use(sessionStore()).post(revokeRoute, {
10903
+ cookie: t24.Cookie({
10904
+ auth_client: authClientOption,
10905
+ auth_provider: authProviderOption,
10906
+ user_session_id: userSessionIdTypebox
10907
+ })
10908
+ }, async ({
10898
10909
  status,
10899
10910
  store: { session },
10900
10911
  cookie: { user_session_id, auth_provider, auth_client }
@@ -10960,12 +10971,6 @@ var revoke = ({
10960
10971
  });
10961
10972
  return status("Internal Server Error", "Failed to revoke token");
10962
10973
  }
10963
- }, {
10964
- cookie: t24.Cookie({
10965
- auth_client: authClientOption,
10966
- auth_provider: authProviderOption,
10967
- user_session_id: userSessionIdTypebox
10968
- })
10969
10974
  });
10970
10975
 
10971
10976
  // src/routes/sessions.ts
@@ -10974,7 +10979,7 @@ var sessionRoutes = ({
10974
10979
  authSessionStore,
10975
10980
  getUserId,
10976
10981
  sessionsRoute = "/auth/sessions"
10977
- }) => new Elysia32().use(sessionStore()).get(sessionsRoute, async ({
10982
+ }) => new Elysia32().use(sessionStore()).get(sessionsRoute, { cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
10978
10983
  cookie: { user_session_id },
10979
10984
  status,
10980
10985
  store: { session }
@@ -11002,7 +11007,10 @@ var sessionRoutes = ({
11002
11007
  id: entry.id
11003
11008
  }));
11004
11009
  return status("OK", { sessions: list });
11005
- }, { cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(`${sessionsRoute}/:id`, async ({
11010
+ }).delete(`${sessionsRoute}/:id`, {
11011
+ cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }),
11012
+ params: t25.Object({ id: t25.String() })
11013
+ }, async ({
11006
11014
  cookie: { user_session_id },
11007
11015
  params: { id },
11008
11016
  status,
@@ -11028,9 +11036,6 @@ var sessionRoutes = ({
11028
11036
  }
11029
11037
  await authSessionStore.removeSession(id);
11030
11038
  return status("OK", { revoked: id });
11031
- }, {
11032
- cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }),
11033
- params: t25.Object({ id: t25.String() })
11034
11039
  });
11035
11040
 
11036
11041
  // src/routes/signout.ts
@@ -11064,7 +11069,12 @@ var signout = ({
11064
11069
  authSessionStore,
11065
11070
  signoutRoute = "/oauth2/signout",
11066
11071
  onSignOut
11067
- }) => new Elysia33().use(sessionStore()).delete(signoutRoute, async ({
11072
+ }) => new Elysia33().use(sessionStore()).delete(signoutRoute, {
11073
+ cookie: t26.Cookie({
11074
+ auth_provider: t26.Optional(authProviderOption),
11075
+ user_session_id: t26.Optional(t26.TemplateLiteral("${string}-${string}-${string}-${string}-${string}"))
11076
+ })
11077
+ }, async ({
11068
11078
  status,
11069
11079
  store: { session },
11070
11080
  cookie: { user_session_id, auth_provider }
@@ -11103,12 +11113,7 @@ var signout = ({
11103
11113
  user_session_id.remove();
11104
11114
  auth_provider?.remove();
11105
11115
  return new Response(null, { status: 204 });
11106
- }), {
11107
- cookie: t26.Cookie({
11108
- auth_provider: t26.Optional(authProviderOption),
11109
- user_session_id: t26.Optional(t26.TemplateLiteral("${string}-${string}-${string}-${string}-${string}"))
11110
- })
11111
- });
11116
+ }));
11112
11117
 
11113
11118
  // src/routes/userStatus.ts
11114
11119
  import { Elysia as Elysia34, t as t27 } from "elysia";
@@ -11116,7 +11121,11 @@ var userStatus = ({
11116
11121
  authSessionStore,
11117
11122
  statusRoute = "/oauth2/status",
11118
11123
  onStatus
11119
- }) => new Elysia34().use(sessionStore()).get(statusRoute, async ({ status, cookie: { user_session_id }, store: { session } }) => {
11124
+ }) => new Elysia34().use(sessionStore()).get(statusRoute, { cookie: t27.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
11125
+ status,
11126
+ cookie: { user_session_id },
11127
+ store: { session }
11128
+ }) => {
11120
11129
  const { user, impersonator, error } = await getStatusFromSource({
11121
11130
  authSessionStore,
11122
11131
  session,
@@ -11131,7 +11140,7 @@ var userStatus = ({
11131
11140
  return err instanceof Error ? status("Internal Server Error", `Error: ${err.message} - ${err.stack ?? ""}`) : status("Internal Server Error", `Unknown Error: ${String(err)}`);
11132
11141
  }
11133
11142
  return { impersonator, user };
11134
- }, { cookie: t27.Cookie({ user_session_id: userSessionIdTypebox }) });
11143
+ });
11135
11144
 
11136
11145
  // src/scim/routes.ts
11137
11146
  import { Elysia as Elysia35, t as t28 } from "elysia";
@@ -11607,7 +11616,7 @@ var scimRoutes = ({
11607
11616
  const resourceTypesLocation = (requestUrl) => `${new URL(requestUrl).origin}${scimRoute}/ResourceTypes`;
11608
11617
  const usersEndpoint = `${scimRoute}/Users`;
11609
11618
  const groupsEndpoint = `${scimRoute}/Groups`;
11610
- return new Elysia35().onParse(({ request }, contentType) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
11619
+ return new Elysia35().parse(({ contentType, request }) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
11611
11620
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11612
11621
  if (organizationId === undefined)
11613
11622
  return unauthorized();
@@ -11622,7 +11631,7 @@ var scimRoutes = ({
11622
11631
  }
11623
11632
  const user = await onScimUserCreate({ input, organizationId });
11624
11633
  return scimJson(toUserResource(user, userLocation(request.url, user.id), customAttributes), SCIM_CREATED);
11625
- }).get(usersRoute, async ({ headers, query, request }) => {
11634
+ }).get(usersRoute, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }, async ({ headers, query, request }) => {
11626
11635
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11627
11636
  if (organizationId === undefined)
11628
11637
  return unauthorized();
@@ -11632,7 +11641,7 @@ var scimRoutes = ({
11632
11641
  });
11633
11642
  const resources = users.map((user) => toUserResource(user, userLocation(request.url, user.id), customAttributes));
11634
11643
  return scimJson(listResponse(resources), SCIM_OK);
11635
- }, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }).get(userRoute, async ({ headers, params: { id }, request }) => {
11644
+ }).get(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
11636
11645
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11637
11646
  if (organizationId === undefined)
11638
11647
  return unauthorized();
@@ -11641,7 +11650,7 @@ var scimRoutes = ({
11641
11650
  return scimError(SCIM_NOT_FOUND, "User not found");
11642
11651
  }
11643
11652
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
11644
- }, { params: t28.Object({ id: t28.String() }) }).put(userRoute, async ({ body, headers, params: { id }, request }) => {
11653
+ }).put(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
11645
11654
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11646
11655
  if (organizationId === undefined)
11647
11656
  return unauthorized();
@@ -11658,7 +11667,7 @@ var scimRoutes = ({
11658
11667
  return scimError(SCIM_NOT_FOUND, "User not found");
11659
11668
  }
11660
11669
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
11661
- }, { params: t28.Object({ id: t28.String() }) }).patch(userRoute, async ({ body, headers, params: { id }, request }) => {
11670
+ }).patch(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
11662
11671
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11663
11672
  if (organizationId === undefined)
11664
11673
  return unauthorized();
@@ -11675,13 +11684,13 @@ var scimRoutes = ({
11675
11684
  return scimError(SCIM_NOT_FOUND, "User not found");
11676
11685
  }
11677
11686
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
11678
- }, { params: t28.Object({ id: t28.String() }) }).delete(userRoute, async ({ headers, params: { id } }) => {
11687
+ }).delete(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id } }) => {
11679
11688
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11680
11689
  if (organizationId === undefined)
11681
11690
  return unauthorized();
11682
11691
  await onScimUserDeactivate({ id, organizationId });
11683
11692
  return new Response(null, { status: SCIM_NO_CONTENT });
11684
- }, { params: t28.Object({ id: t28.String() }) }).post(groupsRoute, async ({ body, headers, request }) => {
11693
+ }).post(groupsRoute, async ({ body, headers, request }) => {
11685
11694
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11686
11695
  if (organizationId === undefined)
11687
11696
  return unauthorized();
@@ -11696,7 +11705,7 @@ var scimRoutes = ({
11696
11705
  organizationId
11697
11706
  });
11698
11707
  return scimJson(toGroupResource(group, groupLocation(request.url, group.id)), SCIM_CREATED);
11699
- }).get(groupsRoute, async ({ headers, query, request }) => {
11708
+ }).get(groupsRoute, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }, async ({ headers, query, request }) => {
11700
11709
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11701
11710
  if (organizationId === undefined)
11702
11711
  return unauthorized();
@@ -11708,7 +11717,7 @@ var scimRoutes = ({
11708
11717
  });
11709
11718
  const resources = groups.map((group) => toGroupResource(group, groupLocation(request.url, group.id)));
11710
11719
  return scimJson(listResponse(resources), SCIM_OK);
11711
- }, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }).get(groupRoute, async ({ headers, params: { id }, request }) => {
11720
+ }).get(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
11712
11721
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11713
11722
  if (organizationId === undefined)
11714
11723
  return unauthorized();
@@ -11719,7 +11728,7 @@ var scimRoutes = ({
11719
11728
  return scimError(SCIM_NOT_FOUND, "Group not found");
11720
11729
  }
11721
11730
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
11722
- }, { params: t28.Object({ id: t28.String() }) }).put(groupRoute, async ({ body, headers, params: { id }, request }) => {
11731
+ }).put(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
11723
11732
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11724
11733
  if (organizationId === undefined)
11725
11734
  return unauthorized();
@@ -11738,7 +11747,7 @@ var scimRoutes = ({
11738
11747
  return scimError(SCIM_NOT_FOUND, "Group not found");
11739
11748
  }
11740
11749
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
11741
- }, { params: t28.Object({ id: t28.String() }) }).patch(groupRoute, async ({ body, headers, params: { id }, request }) => {
11750
+ }).patch(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
11742
11751
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11743
11752
  if (organizationId === undefined)
11744
11753
  return unauthorized();
@@ -11758,7 +11767,7 @@ var scimRoutes = ({
11758
11767
  return scimError(SCIM_NOT_FOUND, "Group not found");
11759
11768
  }
11760
11769
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
11761
- }, { params: t28.Object({ id: t28.String() }) }).delete(groupRoute, async ({ headers, params: { id } }) => {
11770
+ }).delete(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id } }) => {
11762
11771
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11763
11772
  if (organizationId === undefined)
11764
11773
  return unauthorized();
@@ -11766,12 +11775,12 @@ var scimRoutes = ({
11766
11775
  return notImplemented();
11767
11776
  await onScimGroupDelete({ id, organizationId });
11768
11777
  return new Response(null, { status: SCIM_NO_CONTENT });
11769
- }, { params: t28.Object({ id: t28.String() }) }).get(schemasRoute, async ({ headers, request }) => {
11778
+ }).get(schemasRoute, async ({ headers, request }) => {
11770
11779
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11771
11780
  if (organizationId === undefined)
11772
11781
  return unauthorized();
11773
11782
  return scimJson(schemaList(schemasLocation(request.url), extensionSchemas), SCIM_OK);
11774
- }).get(schemaRoute, async ({ headers, params: { id }, request }) => {
11783
+ }).get(schemaRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
11775
11784
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11776
11785
  if (organizationId === undefined)
11777
11786
  return unauthorized();
@@ -11780,12 +11789,12 @@ var scimRoutes = ({
11780
11789
  return scimError(SCIM_NOT_FOUND, "Schema not found");
11781
11790
  }
11782
11791
  return scimJson(schema, SCIM_OK);
11783
- }, { params: t28.Object({ id: t28.String() }) }).get(resourceTypesRoute, async ({ headers, request }) => {
11792
+ }).get(resourceTypesRoute, async ({ headers, request }) => {
11784
11793
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11785
11794
  if (organizationId === undefined)
11786
11795
  return unauthorized();
11787
11796
  return scimJson(resourceTypeList(resourceTypesLocation(request.url), usersEndpoint, groupsEndpoint, extensionSchemas), SCIM_OK);
11788
- }).get(resourceTypeRoute, async ({ headers, params: { id }, request }) => {
11797
+ }).get(resourceTypeRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
11789
11798
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
11790
11799
  if (organizationId === undefined)
11791
11800
  return unauthorized();
@@ -11794,7 +11803,7 @@ var scimRoutes = ({
11794
11803
  return scimError(SCIM_NOT_FOUND, "ResourceType not found");
11795
11804
  }
11796
11805
  return scimJson(resourceType, SCIM_OK);
11797
- }, { params: t28.Object({ id: t28.String() }) });
11806
+ });
11798
11807
  };
11799
11808
 
11800
11809
  // src/session/cleanup.ts
@@ -11807,17 +11816,19 @@ var sessionCleanup = ({
11807
11816
  onSessionCleanup
11808
11817
  }) => {
11809
11818
  let intervalId = null;
11810
- return new Elysia36({ name: "sessionCleanup" }).use(sessionStore()).onStart(({ store: { session, unregisteredSession } }) => {
11819
+ const sessionState = {};
11820
+ const unregisteredSessionState = {};
11821
+ return new Elysia36({ name: "sessionCleanup" }).use(sessionStore(sessionState, unregisteredSessionState)).setup(() => {
11811
11822
  intervalId = setInterval(async () => {
11812
11823
  await performCleanup({
11813
11824
  authSessionStore,
11814
11825
  maxSessions,
11815
11826
  onSessionCleanup,
11816
- session,
11817
- unregisteredSession
11827
+ session: sessionState,
11828
+ unregisteredSession: unregisteredSessionState
11818
11829
  });
11819
11830
  }, cleanupIntervalMs);
11820
- }).onStop(() => {
11831
+ }).cleanup(() => {
11821
11832
  if (intervalId) {
11822
11833
  clearInterval(intervalId);
11823
11834
  intervalId = null;
@@ -12053,7 +12064,7 @@ var ssoDiscoveryRoute = ({
12053
12064
  ssoRoute = DEFAULT_SSO_ROUTE
12054
12065
  }) => {
12055
12066
  const discoveryRoute = `${ssoRoute}/authorize`;
12056
- return new Elysia37().get(discoveryRoute, async ({ query: { email }, redirect, status }) => {
12067
+ return new Elysia37().get(discoveryRoute, { query: t29.Object({ email: t29.Optional(t29.String()) }) }, async ({ query: { email }, redirect, status }) => {
12057
12068
  if (!isNonEmptyString(email)) {
12058
12069
  return status("Bad Request", 'An "email" query parameter is required');
12059
12070
  }
@@ -12070,7 +12081,7 @@ var ssoDiscoveryRoute = ({
12070
12081
  return status("Not Found", "No SSO connection is configured for this organization");
12071
12082
  }
12072
12083
  return redirect(`${ssoRoute}/${connection.type}/${organizationId}/authorize`);
12073
- }, { query: t29.Object({ email: t29.Optional(t29.String()) }) });
12084
+ });
12074
12085
  };
12075
12086
 
12076
12087
  // src/sso/oidcRoutes.ts
@@ -12114,7 +12125,10 @@ var oidcSsoRoutes = ({
12114
12125
  const ssoCookieOptions = makeSsoCookieOptions(resolveCookieSecure(cookieSecure));
12115
12126
  const authorizeRoute = `${ssoRoute}/oidc/:organizationId/authorize`;
12116
12127
  const callbackRoute = `${ssoRoute}/oidc/:organizationId/callback`;
12117
- return new Elysia38().use(sessionStore()).get(authorizeRoute, async ({
12128
+ return new Elysia38().use(sessionStore()).get(authorizeRoute, {
12129
+ cookie: ssoCookieSchema,
12130
+ params: t30.Object({ organizationId: t30.String() })
12131
+ }, async ({
12118
12132
  cookie: {
12119
12133
  sso_nonce,
12120
12134
  sso_organization,
@@ -12152,10 +12166,14 @@ var oidcSsoRoutes = ({
12152
12166
  state
12153
12167
  });
12154
12168
  return redirect(authorizationUrl.toString());
12155
- }, {
12169
+ }).get(callbackRoute, {
12156
12170
  cookie: ssoCookieSchema,
12157
- params: t30.Object({ organizationId: t30.String() })
12158
- }).get(callbackRoute, async ({
12171
+ params: t30.Object({ organizationId: t30.String() }),
12172
+ query: t30.Object({
12173
+ code: t30.Optional(t30.String()),
12174
+ state: t30.Optional(t30.String())
12175
+ })
12176
+ }, async ({
12159
12177
  cookie: {
12160
12178
  sso_nonce,
12161
12179
  sso_organization,
@@ -12229,13 +12247,6 @@ var oidcSsoRoutes = ({
12229
12247
  await onSsoCallbackError?.({ error, organizationId });
12230
12248
  return status("Internal Server Error", "OIDC sign-in failed");
12231
12249
  }
12232
- }, {
12233
- cookie: ssoCookieSchema,
12234
- params: t30.Object({ organizationId: t30.String() }),
12235
- query: t30.Object({
12236
- code: t30.Optional(t30.String()),
12237
- state: t30.Optional(t30.String())
12238
- })
12239
12250
  });
12240
12251
  };
12241
12252
 
@@ -12285,7 +12296,7 @@ var samlSsoRoutes = ({
12285
12296
  const target = authSessionStore ? compatibilityLayer.session : inMemorySession;
12286
12297
  return target[userSessionId]?.samlLogout;
12287
12298
  };
12288
- return new Elysia39().use(sessionStore()).get(authorizeRoute, async ({
12299
+ return new Elysia39().use(sessionStore()).get(authorizeRoute, { params: t31.Object({ organizationId: t31.String() }) }, async ({
12289
12300
  headers,
12290
12301
  params: { organizationId },
12291
12302
  redirect,
@@ -12302,7 +12313,16 @@ var samlSsoRoutes = ({
12302
12313
  relayState: refererPath(headers["referer"])
12303
12314
  });
12304
12315
  return redirect(url);
12305
- }, { params: t31.Object({ organizationId: t31.String() }) }).post(acsRoute, async ({
12316
+ }).post(acsRoute, {
12317
+ body: t31.Object({
12318
+ RelayState: t31.Optional(t31.String()),
12319
+ SAMLResponse: t31.String()
12320
+ }),
12321
+ cookie: t31.Cookie({
12322
+ user_session_id: t31.Optional(userSessionIdTypebox)
12323
+ }),
12324
+ params: t31.Object({ organizationId: t31.String() })
12325
+ }, async ({
12306
12326
  body,
12307
12327
  cookie: { user_session_id },
12308
12328
  params: { organizationId },
@@ -12355,16 +12375,7 @@ var samlSsoRoutes = ({
12355
12375
  await onSsoCallbackError?.({ error, organizationId });
12356
12376
  return status("Internal Server Error", "SAML sign-in failed");
12357
12377
  }
12358
- }, {
12359
- body: t31.Object({
12360
- RelayState: t31.Optional(t31.String()),
12361
- SAMLResponse: t31.String()
12362
- }),
12363
- cookie: t31.Cookie({
12364
- user_session_id: t31.Optional(userSessionIdTypebox)
12365
- }),
12366
- params: t31.Object({ organizationId: t31.String() })
12367
- }).get(metadataRoute, async ({ params: { organizationId }, request, status }) => {
12378
+ }).get(metadataRoute, { params: t31.Object({ organizationId: t31.String() }) }, async ({ params: { organizationId }, request, status }) => {
12368
12379
  const connection = await ssoConnectionStore.getConnectionByOrganization(organizationId, "saml");
12369
12380
  if (connection === undefined || connection.type !== "saml") {
12370
12381
  return status("Not Found", "No SAML connection is configured for this organization");
@@ -12377,7 +12388,12 @@ var samlSsoRoutes = ({
12377
12388
  return new Response(metadata, {
12378
12389
  headers: { "content-type": "application/xml" }
12379
12390
  });
12380
- }, { params: t31.Object({ organizationId: t31.String() }) }).get(logoutRoute, async ({
12391
+ }).get(logoutRoute, {
12392
+ cookie: t31.Cookie({
12393
+ user_session_id: t31.Optional(userSessionIdTypebox)
12394
+ }),
12395
+ params: t31.Object({ organizationId: t31.String() })
12396
+ }, async ({
12381
12397
  cookie: { user_session_id },
12382
12398
  params: { organizationId },
12383
12399
  redirect,
@@ -12404,12 +12420,19 @@ var samlSsoRoutes = ({
12404
12420
  return redirect(url);
12405
12421
  }
12406
12422
  return redirect(idpSloUrl ?? "/");
12407
- }, {
12423
+ }).get(sloRoute, {
12408
12424
  cookie: t31.Cookie({
12409
12425
  user_session_id: t31.Optional(userSessionIdTypebox)
12410
12426
  }),
12411
- params: t31.Object({ organizationId: t31.String() })
12412
- }).get(sloRoute, async ({
12427
+ params: t31.Object({ organizationId: t31.String() }),
12428
+ query: t31.Object({
12429
+ RelayState: t31.Optional(t31.String()),
12430
+ SAMLRequest: t31.Optional(t31.String()),
12431
+ SAMLResponse: t31.Optional(t31.String()),
12432
+ SigAlg: t31.Optional(t31.String()),
12433
+ Signature: t31.Optional(t31.String())
12434
+ })
12435
+ }, async ({
12413
12436
  cookie: { user_session_id },
12414
12437
  params: { organizationId },
12415
12438
  query: {
@@ -12490,18 +12513,6 @@ var samlSsoRoutes = ({
12490
12513
  return redirect(url);
12491
12514
  }
12492
12515
  return redirect(toSafeLocalPath(info.relayState ?? RelayState));
12493
- }, {
12494
- cookie: t31.Cookie({
12495
- user_session_id: t31.Optional(userSessionIdTypebox)
12496
- }),
12497
- params: t31.Object({ organizationId: t31.String() }),
12498
- query: t31.Object({
12499
- RelayState: t31.Optional(t31.String()),
12500
- SAMLRequest: t31.Optional(t31.String()),
12501
- SAMLResponse: t31.Optional(t31.String()),
12502
- SigAlg: t31.Optional(t31.String()),
12503
- Signature: t31.Optional(t31.String())
12504
- })
12505
12516
  });
12506
12517
  };
12507
12518
 
@@ -12549,7 +12560,7 @@ var webauthnRoutes = ({
12549
12560
  secure,
12550
12561
  value: challenge
12551
12562
  });
12552
- return new Elysia40().use(sessionStore()).post(`${webauthnRoute}/register/options`, async ({
12563
+ return new Elysia40().use(sessionStore()).post(`${webauthnRoute}/register/options`, { cookie: challengeCookie }, async ({
12553
12564
  cookie: { user_session_id, webauthn_challenge },
12554
12565
  status,
12555
12566
  store: { session }
@@ -12578,7 +12589,10 @@ var webauthnRoutes = ({
12578
12589
  });
12579
12590
  setChallenge(webauthn_challenge, challenge);
12580
12591
  return status("OK", options);
12581
- }, { cookie: challengeCookie }).post(`${webauthnRoute}/register/verify`, async ({
12592
+ }).post(`${webauthnRoute}/register/verify`, {
12593
+ body: t32.Object({}, { additionalProperties: true }),
12594
+ cookie: challengeCookie
12595
+ }, async ({
12582
12596
  body,
12583
12597
  cookie: { user_session_id, webauthn_challenge },
12584
12598
  status,
@@ -12626,17 +12640,17 @@ var webauthnRoutes = ({
12626
12640
  credentialId: result.credential.credentialId,
12627
12641
  verified: true
12628
12642
  });
12629
- }, {
12630
- body: t32.Object({}, { additionalProperties: true }),
12631
- cookie: challengeCookie
12632
- }).post(`${webauthnRoute}/authenticate/options`, async ({ cookie: { webauthn_challenge }, status }) => {
12643
+ }).post(`${webauthnRoute}/authenticate/options`, { cookie: challengeCookie }, async ({ cookie: { webauthn_challenge }, status }) => {
12633
12644
  const { challenge, options } = await webauthnAdapter.createAuthenticationOptions({
12634
12645
  allowCredentials: [],
12635
12646
  rpId
12636
12647
  });
12637
12648
  setChallenge(webauthn_challenge, challenge);
12638
12649
  return status("OK", options);
12639
- }, { cookie: challengeCookie }).post(`${webauthnRoute}/authenticate/verify`, async ({
12650
+ }).post(`${webauthnRoute}/authenticate/verify`, {
12651
+ body: t32.Object({ id: t32.String() }, { additionalProperties: true }),
12652
+ cookie: challengeCookie
12653
+ }, async ({
12640
12654
  body,
12641
12655
  cookie: { user_session_id, webauthn_challenge },
12642
12656
  status,
@@ -12690,9 +12704,6 @@ var webauthnRoutes = ({
12690
12704
  });
12691
12705
  await onWebAuthnAuthenticated?.({ user, userSessionId });
12692
12706
  return status("OK", { status: "authenticated" });
12693
- }, {
12694
- body: t32.Object({ id: t32.String() }, { additionalProperties: true }),
12695
- cookie: challengeCookie
12696
12707
  });
12697
12708
  };
12698
12709
 
@@ -31572,7 +31583,7 @@ var createNeonLinkedProviderGrantStore = (db) => ({
31572
31583
  owner_ref: grant.ownerRef,
31573
31584
  provider_family: grant.providerFamily,
31574
31585
  provider_subject: grant.providerSubject,
31575
- refresh_token_ciphertext: grant.refreshTokenCiphertext ?? null,
31586
+ refresh_token_ciphertext: sql`coalesce(excluded.refresh_token_ciphertext, ${linkedProviderGrantsTable.refresh_token_ciphertext})`,
31576
31587
  status: grant.status,
31577
31588
  token_type: grant.tokenType ?? null,
31578
31589
  updated_at: new Date(grant.updatedAt)
@@ -31631,7 +31642,11 @@ var createInMemoryLinkedProviderStores = (input = {}) => {
31631
31642
  [...bindings.entries()].filter(([, binding]) => binding.grantId === id).forEach(([bindingId2]) => bindings.delete(bindingId2));
31632
31643
  },
31633
31644
  saveGrant: async (grant) => {
31634
- grants.set(grant.id, cloneGrant(grant));
31645
+ const existing = grants.get(grant.id);
31646
+ grants.set(grant.id, cloneGrant({
31647
+ ...grant,
31648
+ refreshTokenCiphertext: grant.refreshTokenCiphertext ?? existing?.refreshTokenCiphertext
31649
+ }));
31635
31650
  }
31636
31651
  };
31637
31652
  const bindingStore = {
@@ -31657,14 +31672,17 @@ var requireAuthPlugin = ({
31657
31672
  } = {}) => new Elysia41({
31658
31673
  name: "@absolutejs/auth/require-auth",
31659
31674
  seed: pluginDependencySeed(authSessionStore)
31660
- }).use(sessionStore()).guard({ cookie: t33.Cookie({ user_session_id: userSessionIdTypebox }) }).resolve(async ({ store: { session }, cookie: { user_session_id } }) => {
31675
+ }).use(sessionStore()).guard({
31676
+ cookie: t33.Cookie({ user_session_id: userSessionIdTypebox }),
31677
+ schema: "merge"
31678
+ }).derive(async ({ store: { session }, cookie: { user_session_id } }) => {
31661
31679
  const { user } = await getStatusFromSource({
31662
31680
  authSessionStore,
31663
31681
  session,
31664
31682
  user_session_id
31665
31683
  });
31666
31684
  return { user: user ?? null };
31667
- }).onBeforeHandle(({ user, status }) => user === null ? status("Unauthorized", "User is not authenticated") : undefined).as("global");
31685
+ }).beforeHandle(({ user, status }) => user === null ? status("Unauthorized", "User is not authenticated") : undefined).as("global");
31668
31686
  // src/session/impersonation.ts
31669
31687
  init_constants();
31670
31688
  var DEFAULT_IMPERSONATION_TTL_MS = MILLISECONDS_IN_AN_HOUR;
@@ -33116,7 +33134,15 @@ var vciRoutes = ({
33116
33134
  config: vciConfig,
33117
33135
  issuer: issuerUrl,
33118
33136
  vciRoute
33119
- }))).post(credentialRoute, async ({ body, headers }) => {
33137
+ }))).post(credentialRoute, {
33138
+ body: t34.Object({
33139
+ format: t34.Optional(t34.Union([t34.Literal("vc+sd-jwt")])),
33140
+ proof: t34.Optional(t34.Object({
33141
+ jwt: t34.String(),
33142
+ proof_type: t34.Literal("jwt")
33143
+ }))
33144
+ })
33145
+ }, async ({ body, headers }) => {
33120
33146
  const accessToken = extractBearer(headers.authorization);
33121
33147
  if (accessToken === undefined) {
33122
33148
  return errorBody("invalid_token", HTTP_UNAUTHORIZED5);
@@ -33134,14 +33160,6 @@ var vciRoutes = ({
33134
33160
  if (!result.ok)
33135
33161
  return errorBody(result.error, HTTP_BAD_REQUEST4);
33136
33162
  return Response.json({ credential: result.credential, format: result.format }, { status: HTTP_OK4 });
33137
- }, {
33138
- body: t34.Object({
33139
- format: t34.Optional(t34.Union([t34.Literal("vc+sd-jwt")])),
33140
- proof: t34.Optional(t34.Object({
33141
- jwt: t34.String(),
33142
- proof_type: t34.Literal("jwt")
33143
- }))
33144
- })
33145
33163
  }).post(nonceRoute, async () => {
33146
33164
  if (vciConfig.credentialNonceStore === undefined) {
33147
33165
  return errorBody("not_supported", HTTP_BAD_REQUEST4);
@@ -33273,7 +33291,7 @@ var statusListRoutes = ({
33273
33291
  ttlSeconds
33274
33292
  }) => {
33275
33293
  const listRoute = `${statusRoute}/:listId`;
33276
- return new Elysia43().get(listRoute, async ({ params: { listId } }) => {
33294
+ return new Elysia43().get(listRoute, { params: t35.Object({ listId: t35.String() }) }, async ({ params: { listId } }) => {
33277
33295
  const bits = await getStatusList(listId);
33278
33296
  if (bits === undefined) {
33279
33297
  return new Response("Not found", { status: HTTP_NOT_FOUND });
@@ -33289,7 +33307,7 @@ var statusListRoutes = ({
33289
33307
  headers: { "content-type": STATUS_LIST_SUB_TYP },
33290
33308
  status: HTTP_OK5
33291
33309
  });
33292
- }, { params: t35.Object({ listId: t35.String() }) });
33310
+ });
33293
33311
  };
33294
33312
  // src/vc/openid4vp.ts
33295
33313
  init_crypto();
@@ -33513,7 +33531,13 @@ var vpRoutes = ({
33513
33531
  const authorizeRoute = `${vpRoute}/authorize`;
33514
33532
  const requestRoute = `${vpRoute}/request/:id`;
33515
33533
  const responseRoute = `${vpRoute}/response`;
33516
- return new Elysia44().post(authorizeRoute, async ({ body }) => {
33534
+ return new Elysia44().post(authorizeRoute, {
33535
+ body: t36.Object({
33536
+ client_id: t36.Optional(t36.String()),
33537
+ requested_claims: t36.Array(t36.String()),
33538
+ state: t36.Optional(t36.String())
33539
+ })
33540
+ }, async ({ body }) => {
33517
33541
  const input = {
33518
33542
  clientId: body.client_id ?? defaultClientId,
33519
33543
  requestedClaims: body.requested_claims,
@@ -33530,13 +33554,7 @@ var vpRoutes = ({
33530
33554
  request_uri: result.requestUri,
33531
33555
  requestId: result.request.requestId
33532
33556
  }, { status: HTTP_OK6 });
33533
- }, {
33534
- body: t36.Object({
33535
- client_id: t36.Optional(t36.String()),
33536
- requested_claims: t36.Array(t36.String()),
33537
- state: t36.Optional(t36.String())
33538
- })
33539
- }).get(requestRoute, async ({ params: { id } }) => {
33557
+ }).get(requestRoute, { params: t36.Object({ id: t36.String() }) }, async ({ params: { id } }) => {
33540
33558
  const stored = await vpConfig.requestStore.getRequest(id);
33541
33559
  if (stored === undefined) {
33542
33560
  return errorBody2("unknown_request", HTTP_NOT_FOUND2);
@@ -33560,7 +33578,13 @@ var vpRoutes = ({
33560
33578
  },
33561
33579
  status: HTTP_OK6
33562
33580
  });
33563
- }, { params: t36.Object({ id: t36.String() }) }).post(responseRoute, async ({ body }) => {
33581
+ }).post(responseRoute, {
33582
+ body: t36.Object({
33583
+ presentation_submission: t36.Optional(t36.Unknown()),
33584
+ state: t36.Optional(t36.String()),
33585
+ vp_token: t36.String()
33586
+ })
33587
+ }, async ({ body }) => {
33564
33588
  const requestId = body.state;
33565
33589
  if (requestId === undefined) {
33566
33590
  return errorBody2("missing_state", HTTP_BAD_REQUEST5);
@@ -33580,12 +33604,6 @@ var vpRoutes = ({
33580
33604
  protected_claims: result.verified.protectedClaims,
33581
33605
  verified: true
33582
33606
  }, { status: HTTP_OK6 });
33583
- }, {
33584
- body: t36.Object({
33585
- presentation_submission: t36.Optional(t36.Unknown()),
33586
- state: t36.Optional(t36.String()),
33587
- vp_token: t36.String()
33588
- })
33589
33607
  });
33590
33608
  };
33591
33609
  var passthroughStore = (request) => ({
@@ -37060,13 +37078,7 @@ var samlIdpRoutes = ({
37060
37078
  user: userSession.user
37061
37079
  });
37062
37080
  };
37063
- return new Elysia45().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
37064
- binding: "POST",
37065
- body,
37066
- inMemorySession: store.session,
37067
- request,
37068
- userSessionIdValue: user_session_id.value
37069
- }), {
37081
+ return new Elysia45().use(sessionStore()).post(ssoIdpRoute, {
37070
37082
  body: t37.Object({
37071
37083
  RelayState: t37.Optional(t37.String()),
37072
37084
  SAMLRequest: t37.Optional(t37.String())
@@ -37074,13 +37086,13 @@ var samlIdpRoutes = ({
37074
37086
  cookie: t37.Cookie({
37075
37087
  user_session_id: t37.Optional(userSessionIdTypebox)
37076
37088
  })
37077
- }).get(ssoIdpRoute, async ({ cookie: { user_session_id }, query, request, store }) => handleSpInitiated({
37078
- binding: "Redirect",
37079
- body: query,
37089
+ }, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
37090
+ binding: "POST",
37091
+ body,
37080
37092
  inMemorySession: store.session,
37081
37093
  request,
37082
37094
  userSessionIdValue: user_session_id.value
37083
- }), {
37095
+ })).get(ssoIdpRoute, {
37084
37096
  cookie: t37.Cookie({
37085
37097
  user_session_id: t37.Optional(userSessionIdTypebox)
37086
37098
  }),
@@ -37090,7 +37102,21 @@ var samlIdpRoutes = ({
37090
37102
  SigAlg: t37.Optional(t37.String()),
37091
37103
  Signature: t37.Optional(t37.String())
37092
37104
  })
37093
- }).get(idpInitiateRoute, async ({
37105
+ }, async ({ cookie: { user_session_id }, query, request, store }) => handleSpInitiated({
37106
+ binding: "Redirect",
37107
+ body: query,
37108
+ inMemorySession: store.session,
37109
+ request,
37110
+ userSessionIdValue: user_session_id.value
37111
+ })).get(idpInitiateRoute, {
37112
+ cookie: t37.Cookie({
37113
+ user_session_id: t37.Optional(userSessionIdTypebox)
37114
+ }),
37115
+ query: t37.Object({
37116
+ RelayState: t37.Optional(t37.String()),
37117
+ sp: t37.Optional(t37.String())
37118
+ })
37119
+ }, async ({
37094
37120
  cookie: { user_session_id },
37095
37121
  query: { sp: serviceProviderEntityId, RelayState: relayState },
37096
37122
  request,
@@ -37123,14 +37149,6 @@ var samlIdpRoutes = ({
37123
37149
  serviceProviderEntityId: serviceProvider.entityId,
37124
37150
  user: userSession.user
37125
37151
  });
37126
- }, {
37127
- cookie: t37.Cookie({
37128
- user_session_id: t37.Optional(userSessionIdTypebox)
37129
- }),
37130
- query: t37.Object({
37131
- RelayState: t37.Optional(t37.String()),
37132
- sp: t37.Optional(t37.String())
37133
- })
37134
37152
  }).get(idpMetadataRoute, async ({ request }) => xmlResponse(await idpAdapter.getIdpMetadata({
37135
37153
  entityId: idpEntityId,
37136
37154
  ssoUrl: ssoUrlFor(request.url)
@@ -37635,10 +37653,7 @@ var buildAuthApplications = async (configuration) => {
37635
37653
  profileRoute
37636
37654
  })
37637
37655
  ]);
37638
- const featureRoutes = new Elysia46({
37639
- name: "@absolutejs/auth/feature-routes",
37640
- seed: pluginSeed
37641
- }).use([
37656
+ const identityFeatureRoutes = new Elysia46().use([
37642
37657
  auditedCredentials ? credentialRoutes({
37643
37658
  ...auditedCredentials,
37644
37659
  authSessionStore,
@@ -37668,7 +37683,9 @@ var buildAuthApplications = async (configuration) => {
37668
37683
  authSessionStore,
37669
37684
  cookieSecure: resolvedCookieSecure,
37670
37685
  samlAdapter: sso.samlAdapter
37671
- }) : new Elysia46,
37686
+ }) : new Elysia46
37687
+ ]);
37688
+ const organizationFeatureRoutes = new Elysia46().use([
37672
37689
  sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
37673
37690
  getOrganizationByEmailDomain: sso.getOrganizationByEmailDomain,
37674
37691
  ssoConnectionStore: sso.ssoConnectionStore,
@@ -37689,7 +37706,9 @@ var buildAuthApplications = async (configuration) => {
37689
37706
  ...roles,
37690
37707
  authSessionStore,
37691
37708
  emit: auditEmit
37692
- }) : new Elysia46,
37709
+ }) : new Elysia46
37710
+ ]);
37711
+ const extendedFeatureRoutes = new Elysia46().use([
37693
37712
  portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia46,
37694
37713
  webauthn ? webauthnRoutes({
37695
37714
  ...webauthn,
@@ -37705,6 +37724,14 @@ var buildAuthApplications = async (configuration) => {
37705
37724
  createConfiguredAuthHtmxRoutes({ authSessionStore, config: htmx }),
37706
37725
  agentAuthRoutes(resolvedAgentAuth)
37707
37726
  ]);
37727
+ const featureRoutes = new Elysia46({
37728
+ name: "@absolutejs/auth/feature-routes",
37729
+ seed: pluginSeed
37730
+ }).use([
37731
+ identityFeatureRoutes,
37732
+ organizationFeatureRoutes,
37733
+ extendedFeatureRoutes
37734
+ ]);
37708
37735
  const authContext = createAuthContext({
37709
37736
  agentAuth: resolvedAgentAuth,
37710
37737
  authorization,
@@ -38236,5 +38263,5 @@ export {
38236
38263
  AGENT_CLAIM_GRANT_TYPE
38237
38264
  };
38238
38265
 
38239
- //# debugId=BB9E2E153512DF2164756E2164756E21
38266
+ //# debugId=E40C83F26EA3C8B964756E2164756E21
38240
38267
  //# sourceMappingURL=index.js.map