@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/server.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);
@@ -4155,7 +4155,14 @@ var apiKeysRoutes = ({
4155
4155
  if (apiClientStore === undefined || accessTokenStore === undefined) {
4156
4156
  return new Elysia;
4157
4157
  }
4158
- return new Elysia().post(tokenRoute, async ({ body, headers }) => {
4158
+ return new Elysia().post(tokenRoute, {
4159
+ body: t.Object({
4160
+ client_id: t.Optional(t.String()),
4161
+ client_secret: t.Optional(t.String()),
4162
+ grant_type: t.Optional(t.String()),
4163
+ scope: t.Optional(t.String())
4164
+ })
4165
+ }, async ({ body, headers }) => {
4159
4166
  if (body.grant_type !== GRANT_CLIENT_CREDENTIALS) {
4160
4167
  return oauthError(HTTP_BAD_REQUEST, "unsupported_grant_type");
4161
4168
  }
@@ -4188,13 +4195,6 @@ var apiKeysRoutes = ({
4188
4195
  },
4189
4196
  status: HTTP_OK
4190
4197
  });
4191
- }, {
4192
- body: t.Object({
4193
- client_id: t.Optional(t.String()),
4194
- client_secret: t.Optional(t.String()),
4195
- grant_type: t.Optional(t.String()),
4196
- scope: t.Optional(t.String())
4197
- })
4198
4198
  });
4199
4199
  };
4200
4200
 
@@ -5542,14 +5542,10 @@ var loadSessionFromSource = async ({
5542
5542
 
5543
5543
  // src/session/state.ts
5544
5544
  import { Elysia as Elysia4 } from "elysia";
5545
- var sessionStore = () => {
5546
- const initialSession = {};
5547
- const initialUnregisteredSession = {};
5548
- return new Elysia4({ name: "sessionStore" }).state({
5549
- session: initialSession,
5550
- unregisteredSession: initialUnregisteredSession
5551
- });
5552
- };
5545
+ var sessionStore = (initialSession = {}, initialUnregisteredSession = {}) => new Elysia4({ name: "sessionStore" }).state({
5546
+ session: initialSession,
5547
+ unregisteredSession: initialUnregisteredSession
5548
+ });
5553
5549
 
5554
5550
  // src/typebox.ts
5555
5551
  import { t as t2 } from "elysia";
@@ -5570,7 +5566,10 @@ var protectPermissionPlugin = ({
5570
5566
  }) => new Elysia5({
5571
5567
  name: "@absolutejs/auth/permission",
5572
5568
  seed: pluginDependencySeed(hasPermission)
5573
- }).use(sessionStore()).guard({ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5569
+ }).use(sessionStore()).guard({
5570
+ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }),
5571
+ schema: "merge"
5572
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5574
5573
  protectPermission: (check, handleAuth, handleAuthFail) => getStatusFromSource({
5575
5574
  authSessionStore,
5576
5575
  session,
@@ -5613,7 +5612,10 @@ var protectRoutePlugin = ({
5613
5612
  } = {}) => new Elysia6({
5614
5613
  name: "@absolutejs/auth/protect-route",
5615
5614
  seed: pluginDependencySeed(authSessionStore)
5616
- }).use(sessionStore()).guard({ cookie: t4.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5615
+ }).use(sessionStore()).guard({
5616
+ cookie: t4.Cookie({ user_session_id: userSessionIdTypebox }),
5617
+ schema: "merge"
5618
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5617
5619
  protectRoute: (handleAuth, handleAuthFail) => getStatusFromSource({
5618
5620
  authSessionStore,
5619
5621
  session,
@@ -5639,7 +5641,10 @@ var stepUpPlugin = ({
5639
5641
  } = {}) => new Elysia7({
5640
5642
  name: "@absolutejs/auth/step-up",
5641
5643
  seed: pluginDependencySeed(authSessionStore)
5642
- }).use(sessionStore()).guard({ cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5644
+ }).use(sessionStore()).guard({
5645
+ cookie: t5.Cookie({ user_session_id: userSessionIdTypebox }),
5646
+ schema: "merge"
5647
+ }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
5643
5648
  requireRecentAuth: (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
5644
5649
  authSessionStore,
5645
5650
  session,
@@ -5685,7 +5690,7 @@ import { Elysia as Elysia9, t as t6 } from "elysia";
5685
5690
  init_constants();
5686
5691
 
5687
5692
  // src/types.ts
5688
- function isJsonValue(value) {
5693
+ var isJsonValue = (value) => {
5689
5694
  if (value === null || typeof value === "boolean" || typeof value === "string")
5690
5695
  return true;
5691
5696
  if (typeof value === "number")
@@ -5695,7 +5700,7 @@ function isJsonValue(value) {
5695
5700
  if (typeof value !== "object")
5696
5701
  return false;
5697
5702
  return Object.values(value).every(isJsonValue);
5698
- }
5703
+ };
5699
5704
  var parseJsonObject = (value) => {
5700
5705
  if (!isJsonValue(value) || value === null || Array.isArray(value) || typeof value !== "object")
5701
5706
  throw new TypeError("Expected a JSON object");
@@ -6049,7 +6054,7 @@ var complianceRoutes = ({
6049
6054
  emit,
6050
6055
  exportUserData,
6051
6056
  getUserId
6052
- }) => new Elysia9().use(sessionStore()).get(`${complianceRoute}/export`, async ({
6057
+ }) => new Elysia9().use(sessionStore()).get(`${complianceRoute}/export`, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
6053
6058
  cookie: { user_session_id },
6054
6059
  status,
6055
6060
  store: { session }
@@ -6069,7 +6074,7 @@ var complianceRoutes = ({
6069
6074
  userId: getUserId?.(current.user)
6070
6075
  });
6071
6076
  return status("OK", data);
6072
- }, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(complianceRoute, async ({
6077
+ }).delete(complianceRoute, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
6073
6078
  cookie: { user_session_id },
6074
6079
  status,
6075
6080
  store: { session }
@@ -6102,7 +6107,7 @@ var complianceRoutes = ({
6102
6107
  userId
6103
6108
  });
6104
6109
  return status("OK", { deleted: true });
6105
- }, { cookie: t6.Cookie({ user_session_id: userSessionIdTypebox }) });
6110
+ });
6106
6111
 
6107
6112
  // src/credentials/routes.ts
6108
6113
  import { Elysia as Elysia14 } from "elysia";
@@ -6128,7 +6133,7 @@ var credentialsEmailVerification = ({
6128
6133
  requireEmailVerification = false,
6129
6134
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS,
6130
6135
  verifyEmailRoute = "/auth/verify-email"
6131
- }) => new Elysia10().post(verifyEmailRoute, async ({ body: { token }, status }) => {
6136
+ }) => new Elysia10().post(verifyEmailRoute, { body: t7.Object({ token: t7.String() }) }, async ({ body: { token }, status }) => {
6132
6137
  const consumed = await credentialStore.consumeVerificationToken(await hashToken(token));
6133
6138
  if (!consumed) {
6134
6139
  return status("Bad Request", "Invalid or expired verification token");
@@ -6168,7 +6173,7 @@ var credentialsEmailVerification = ({
6168
6173
  }
6169
6174
  await onEmailVerified?.({ email: consumed.email });
6170
6175
  return status("OK", { status: "email_verified" });
6171
- }, { body: t7.Object({ token: t7.String() }) }).post(`${verifyEmailRoute}/request`, async ({ body: { email }, status }) => {
6176
+ }).post(`${verifyEmailRoute}/request`, { body: t7.Object({ email: t7.String() }) }, async ({ body: { email }, status }) => {
6172
6177
  const normalizedEmail = email.trim().toLowerCase();
6173
6178
  const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
6174
6179
  if (credential && !credential.emailVerified) {
@@ -6187,7 +6192,7 @@ var credentialsEmailVerification = ({
6187
6192
  });
6188
6193
  }
6189
6194
  return status("OK", { status: "verification_requested" });
6190
- }, { body: t7.Object({ email: t7.String() }) });
6195
+ });
6191
6196
 
6192
6197
  // src/credentials/login.ts
6193
6198
  init_constants();
@@ -6301,7 +6306,7 @@ var constantTimeEqualBytes = (left, right) => {
6301
6306
  return diff === 0;
6302
6307
  };
6303
6308
  var base64Decode = (encoded) => new Uint8Array(Buffer.from(encoded, "base64"));
6304
- var sha256Bytes = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", input));
6309
+ var sha256Bytes = async (input) => new Uint8Array(await crypto.subtle.digest("SHA-256", Uint8Array.from(input)));
6305
6310
  var isLegacyHash = (storedHash) => !storedHash.startsWith("$argon2id$") && !storedHash.startsWith("$2");
6306
6311
  var verifyAuth0Pbkdf2 = async (plainPassword, wrappedHash) => {
6307
6312
  const parts = wrappedHash.split(":");
@@ -6425,7 +6430,10 @@ var credentialsLogin = ({
6425
6430
  requireEmailVerification = false,
6426
6431
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
6427
6432
  trustedOrigins
6428
- }) => new Elysia11().use(sessionStore()).post(loginRoute, async ({
6433
+ }) => new Elysia11().use(sessionStore()).post(loginRoute, {
6434
+ body: t8.Object({ email: t8.String(), password: t8.String() }),
6435
+ cookie: t8.Cookie({ user_session_id: userSessionIdTypebox })
6436
+ }, async ({
6429
6437
  body: { email, password },
6430
6438
  cookie: { user_session_id },
6431
6439
  request,
@@ -6521,10 +6529,7 @@ var credentialsLogin = ({
6521
6529
  passwordCompromised,
6522
6530
  status: "authenticated"
6523
6531
  });
6524
- }), {
6525
- body: t8.Object({ email: t8.String(), password: t8.String() }),
6526
- cookie: t8.Cookie({ user_session_id: userSessionIdTypebox })
6527
- });
6532
+ }));
6528
6533
 
6529
6534
  // src/credentials/passwordReset.ts
6530
6535
  init_crypto();
@@ -6536,7 +6541,7 @@ var credentialsPasswordReset = ({
6536
6541
  passwordPolicy,
6537
6542
  resetPasswordRoute = "/auth/reset-password",
6538
6543
  resetTokenDurationMs = DEFAULT_RESET_TOKEN_TTL_MS
6539
- }) => new Elysia12().post(`${resetPasswordRoute}/request`, async ({ body: { email }, status }) => {
6544
+ }) => new Elysia12().post(`${resetPasswordRoute}/request`, { body: t9.Object({ email: t9.String() }) }, async ({ body: { email }, status }) => {
6540
6545
  const normalizedEmail = email.trim().toLowerCase();
6541
6546
  const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
6542
6547
  if (credential && credential.status === "active" && credential.registrationData === undefined) {
@@ -6555,7 +6560,9 @@ var credentialsPasswordReset = ({
6555
6560
  });
6556
6561
  }
6557
6562
  return status("OK", { status: "reset_requested" });
6558
- }, { body: t9.Object({ email: t9.String() }) }).post(resetPasswordRoute, async ({ body: { password, token }, status }) => {
6563
+ }).post(resetPasswordRoute, {
6564
+ body: t9.Object({ password: t9.String(), token: t9.String() })
6565
+ }, async ({ body: { password, token }, status }) => {
6559
6566
  const consumed = await credentialStore.consumeResetToken(await hashToken(token));
6560
6567
  if (!consumed) {
6561
6568
  return status("Bad Request", "Invalid or expired reset token");
@@ -6584,8 +6591,6 @@ var credentialsPasswordReset = ({
6584
6591
  });
6585
6592
  await onPasswordReset?.({ email: consumed.email });
6586
6593
  return status("OK", { status: "password_reset" });
6587
- }, {
6588
- body: t9.Object({ password: t9.String(), token: t9.String() })
6589
6594
  });
6590
6595
 
6591
6596
  // src/credentials/register.ts
@@ -6610,7 +6615,10 @@ var credentialsRegister = ({
6610
6615
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
6611
6616
  trustedOrigins,
6612
6617
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS
6613
- }) => new Elysia13().use(sessionStore()).post(registerRoute, async ({
6618
+ }) => new Elysia13().use(sessionStore()).post(registerRoute, {
6619
+ body: t10.Object({ email: t10.String(), password: t10.String() }, { additionalProperties: true }),
6620
+ cookie: t10.Cookie({ user_session_id: userSessionIdTypebox })
6621
+ }, async ({
6614
6622
  body: { email, password, ...extraFields },
6615
6623
  cookie: { user_session_id },
6616
6624
  request,
@@ -6708,10 +6716,7 @@ var credentialsRegister = ({
6708
6716
  userSessionId
6709
6717
  });
6710
6718
  return status("Created", { status: "authenticated" });
6711
- }), {
6712
- body: t10.Object({ email: t10.String(), password: t10.String() }, { additionalProperties: true }),
6713
- cookie: t10.Cookie({ user_session_id: userSessionIdTypebox })
6714
- });
6719
+ }));
6715
6720
 
6716
6721
  // src/credentials/routes.ts
6717
6722
  var credentialRoutes = (config) => new Elysia14().use(credentialsRegister(config)).use(credentialsEmailVerification(config)).use(credentialsLogin(config)).use(credentialsPasswordReset(config));
@@ -7185,7 +7190,10 @@ var mfaSmsRoutes = ({
7185
7190
  smsResendCooldownMs = DEFAULT_SMS_RESEND_COOLDOWN_MS,
7186
7191
  smsSetupRoute = "/auth/mfa/sms/setup",
7187
7192
  smsVerifyRoute = "/auth/mfa/sms/verify"
7188
- }) => new Elysia17().use(sessionStore()).post(smsSetupRoute, async ({
7193
+ }) => new Elysia17().use(sessionStore()).post(smsSetupRoute, {
7194
+ body: t11.Object({ phone: t11.String() }),
7195
+ cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
7196
+ }, async ({
7189
7197
  body: { phone },
7190
7198
  cookie: { user_session_id },
7191
7199
  status,
@@ -7246,10 +7254,10 @@ var mfaSmsRoutes = ({
7246
7254
  return status(mapped.status, mapped.message);
7247
7255
  }
7248
7256
  return status("OK", { phone: maskPhone(phone) });
7249
- }, {
7250
- body: t11.Object({ phone: t11.String() }),
7257
+ }).post(smsVerifyRoute, {
7258
+ body: t11.Object({ code: t11.String() }),
7251
7259
  cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
7252
- }).post(smsVerifyRoute, async ({
7260
+ }, async ({
7253
7261
  body: { code },
7254
7262
  cookie: { user_session_id },
7255
7263
  status,
@@ -7324,9 +7332,6 @@ var mfaSmsRoutes = ({
7324
7332
  }
7325
7333
  await onMfaEnrolled?.({ userId });
7326
7334
  return status("OK", { status: "enrolled" });
7327
- }, {
7328
- body: t11.Object({ code: t11.String() }),
7329
- cookie: t11.Cookie({ user_session_id: userSessionIdTypebox })
7330
7335
  });
7331
7336
 
7332
7337
  // src/mfa/challenge.ts
@@ -7348,7 +7353,14 @@ var mfaChallenge = ({
7348
7353
  smsMaxAttempts = DEFAULT_SMS_MAX_ATTEMPTS,
7349
7354
  smsResendCooldownMs = DEFAULT_SMS_RESEND_COOLDOWN_MS,
7350
7355
  totpMaxAttempts = DEFAULT_TOTP_MAX_ATTEMPTS
7351
- }) => new Elysia18().use(sessionStore()).post(challengeRoute, async ({
7356
+ }) => new Elysia18().use(sessionStore()).post(challengeRoute, {
7357
+ body: t12.Object({
7358
+ action: t12.Optional(t12.Union([t12.Literal("send"), t12.Literal("verify")])),
7359
+ code: t12.Optional(t12.String()),
7360
+ factor: t12.Optional(t12.Literal("sms"))
7361
+ }),
7362
+ cookie: t12.Cookie({ user_session_id: userSessionIdTypebox })
7363
+ }, async ({
7352
7364
  body: { action, code, factor },
7353
7365
  cookie: { user_session_id },
7354
7366
  status,
@@ -7521,14 +7533,7 @@ var mfaChallenge = ({
7521
7533
  updatedAt: Date.now()
7522
7534
  });
7523
7535
  return promote();
7524
- }), {
7525
- body: t12.Object({
7526
- action: t12.Optional(t12.Union([t12.Literal("send"), t12.Literal("verify")])),
7527
- code: t12.Optional(t12.String()),
7528
- factor: t12.Optional(t12.Literal("sms"))
7529
- }),
7530
- cookie: t12.Cookie({ user_session_id: userSessionIdTypebox })
7531
- });
7536
+ }));
7532
7537
 
7533
7538
  // src/mfa/management.ts
7534
7539
  import { Elysia as Elysia19, t as t13 } from "elysia";
@@ -7545,7 +7550,7 @@ var mfaManagementRoutes = ({
7545
7550
  managementRoute = "/auth/mfa",
7546
7551
  managementAuthMaxAgeMs = DEFAULT_MFA_MANAGEMENT_AUTH_MAX_AGE_MS,
7547
7552
  mfaStore
7548
- }) => new Elysia19().use(sessionStore()).get(managementRoute, async ({
7553
+ }) => new Elysia19().use(sessionStore()).get(managementRoute, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
7549
7554
  cookie: { user_session_id },
7550
7555
  status,
7551
7556
  store: { session }
@@ -7569,7 +7574,7 @@ var mfaManagementRoutes = ({
7569
7574
  totp: { enabled: enrollment?.totpVerified ?? false }
7570
7575
  };
7571
7576
  return status("OK", response);
7572
- }, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(managementRoute, async ({
7577
+ }).delete(managementRoute, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
7573
7578
  cookie: { user_session_id },
7574
7579
  status,
7575
7580
  store: { session }
@@ -7587,7 +7592,7 @@ var mfaManagementRoutes = ({
7587
7592
  }
7588
7593
  await mfaStore.removeEnrollment(getUserId(userSession.user));
7589
7594
  return status("OK", { status: "disabled" });
7590
- }, { cookie: t13.Cookie({ user_session_id: userSessionIdTypebox }) });
7595
+ });
7591
7596
 
7592
7597
  // src/mfa/totp.ts
7593
7598
  init_crypto();
@@ -7603,7 +7608,7 @@ var mfaTotpRoutes = ({
7603
7608
  onMfaEnrolled,
7604
7609
  totpSetupRoute = "/auth/mfa/totp/setup",
7605
7610
  totpVerifyRoute = "/auth/mfa/totp/verify"
7606
- }) => new Elysia20().use(sessionStore()).post(totpSetupRoute, async ({
7611
+ }) => new Elysia20().use(sessionStore()).post(totpSetupRoute, { cookie: t14.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
7607
7612
  cookie: { user_session_id },
7608
7613
  status,
7609
7614
  store: { session }
@@ -7644,7 +7649,10 @@ var mfaTotpRoutes = ({
7644
7649
  secret
7645
7650
  })
7646
7651
  });
7647
- }, { cookie: t14.Cookie({ user_session_id: userSessionIdTypebox }) }).post(totpVerifyRoute, async ({
7652
+ }).post(totpVerifyRoute, {
7653
+ body: t14.Object({ code: t14.String() }),
7654
+ cookie: t14.Cookie({ user_session_id: userSessionIdTypebox })
7655
+ }, async ({
7648
7656
  body: { code },
7649
7657
  cookie: { user_session_id },
7650
7658
  status,
@@ -7680,9 +7688,6 @@ var mfaTotpRoutes = ({
7680
7688
  });
7681
7689
  await onMfaEnrolled?.({ userId });
7682
7690
  return status("OK", { backupCodes: codes });
7683
- }, {
7684
- body: t14.Object({ code: t14.String() }),
7685
- cookie: t14.Cookie({ user_session_id: userSessionIdTypebox })
7686
7691
  });
7687
7692
 
7688
7693
  // src/mfa/routes.ts
@@ -8654,7 +8659,7 @@ var base64UrlEncode2 = (bytes) => {
8654
8659
  return btoa(binary).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
8655
8660
  };
8656
8661
  var computeCertThumbprint = async (derBytes) => {
8657
- const digest = await crypto.subtle.digest("SHA-256", derBytes);
8662
+ const digest = await crypto.subtle.digest("SHA-256", Uint8Array.from(derBytes));
8658
8663
  return base64UrlEncode2(new Uint8Array(digest));
8659
8664
  };
8660
8665
  var extractRfc9440ClientCert = (headers) => {
@@ -9748,7 +9753,30 @@ var oidcProviderRoutes = (config) => {
9748
9753
  url.searchParams.set("state", query.state);
9749
9754
  return redirectTo(url.toString());
9750
9755
  };
9751
- return new Elysia22().use(sessionStore()).get(authorizeRoute, async ({
9756
+ return new Elysia22().use(sessionStore()).get(authorizeRoute, {
9757
+ cookie: t15.Cookie({
9758
+ user_session_id: t15.Optional(userSessionIdTypebox)
9759
+ }),
9760
+ query: t15.Object({
9761
+ acr_values: t15.Optional(t15.String()),
9762
+ claims: t15.Optional(t15.String()),
9763
+ client_id: t15.Optional(t15.String()),
9764
+ code_challenge: t15.Optional(t15.String()),
9765
+ code_challenge_method: t15.Optional(t15.String()),
9766
+ id_token_hint: t15.Optional(t15.String()),
9767
+ max_age: t15.Optional(t15.String()),
9768
+ nonce: t15.Optional(t15.String()),
9769
+ prompt: t15.Optional(t15.String()),
9770
+ redirect_uri: t15.Optional(t15.String()),
9771
+ request: t15.Optional(t15.String()),
9772
+ request_uri: t15.Optional(t15.String()),
9773
+ resource: t15.Optional(t15.String()),
9774
+ response_mode: t15.Optional(t15.String()),
9775
+ response_type: t15.Optional(t15.String()),
9776
+ scope: t15.Optional(t15.String()),
9777
+ state: t15.Optional(t15.String())
9778
+ })
9779
+ }, async ({
9752
9780
  cookie: { user_session_id },
9753
9781
  query,
9754
9782
  request,
@@ -9834,7 +9862,7 @@ var oidcProviderRoutes = (config) => {
9834
9862
  const wantsSilent = promptValues.includes("none");
9835
9863
  const wantsLogin = promptValues.includes("login") || promptValues.includes("consent");
9836
9864
  const maxAge = effectiveQuery.max_age === undefined ? undefined : Number(effectiveQuery.max_age);
9837
- const sessionStaleByMaxAge = userSession !== undefined && maxAge !== undefined && !Number.isNaN(maxAge) && maxAge >= 0 && (userSession.authenticatedAt ?? 0) < Date.now() - maxAge * 1000;
9865
+ const sessionStaleByMaxAge = userSession !== undefined && maxAge !== undefined && !Number.isNaN(maxAge) && maxAge >= 0 && (maxAge === 0 || (userSession.authenticatedAt ?? 0) < Date.now() - maxAge * 1000);
9838
9866
  const hintSub = effectiveQuery.id_token_hint === undefined ? undefined : (await verifyIdTokenHint({
9839
9867
  config,
9840
9868
  idTokenHint: effectiveQuery.id_token_hint
@@ -9909,30 +9937,29 @@ var oidcProviderRoutes = (config) => {
9909
9937
  if (state !== undefined)
9910
9938
  params.state = state;
9911
9939
  return respondToClient(redirectUri, responseMode, params);
9912
- }, {
9913
- cookie: t15.Cookie({
9914
- user_session_id: t15.Optional(userSessionIdTypebox)
9915
- }),
9916
- query: t15.Object({
9917
- acr_values: t15.Optional(t15.String()),
9918
- claims: t15.Optional(t15.String()),
9940
+ }).post(tokenRoute, {
9941
+ body: t15.Object({
9942
+ assertion: t15.Optional(t15.String()),
9943
+ audience: t15.Optional(t15.String()),
9944
+ auth_req_id: t15.Optional(t15.String()),
9945
+ claim_token: t15.Optional(t15.String()),
9946
+ client_assertion: t15.Optional(t15.String()),
9947
+ client_assertion_type: t15.Optional(t15.String()),
9919
9948
  client_id: t15.Optional(t15.String()),
9920
- code_challenge: t15.Optional(t15.String()),
9921
- code_challenge_method: t15.Optional(t15.String()),
9922
- id_token_hint: t15.Optional(t15.String()),
9923
- max_age: t15.Optional(t15.String()),
9924
- nonce: t15.Optional(t15.String()),
9925
- prompt: t15.Optional(t15.String()),
9949
+ client_secret: t15.Optional(t15.String()),
9950
+ code: t15.Optional(t15.String()),
9951
+ code_verifier: t15.Optional(t15.String()),
9952
+ device_code: t15.Optional(t15.String()),
9953
+ grant_type: t15.Optional(t15.String()),
9954
+ "pre-authorized_code": t15.Optional(t15.String()),
9926
9955
  redirect_uri: t15.Optional(t15.String()),
9927
- request: t15.Optional(t15.String()),
9928
- request_uri: t15.Optional(t15.String()),
9956
+ refresh_token: t15.Optional(t15.String()),
9929
9957
  resource: t15.Optional(t15.String()),
9930
- response_mode: t15.Optional(t15.String()),
9931
- response_type: t15.Optional(t15.String()),
9932
9958
  scope: t15.Optional(t15.String()),
9933
- state: t15.Optional(t15.String())
9959
+ subject_token: t15.Optional(t15.String()),
9960
+ subject_token_type: t15.Optional(t15.String())
9934
9961
  })
9935
- }).post(tokenRoute, async ({ body, headers, request }) => {
9962
+ }, async ({ body, headers, request }) => {
9936
9963
  if (body.grant_type === PRE_AUTHORIZED_CODE_GRANT && config.vciConfig !== undefined) {
9937
9964
  const preAuthorizedCode = body["pre-authorized_code"];
9938
9965
  if (typeof preAuthorizedCode !== "string") {
@@ -9996,29 +10023,28 @@ var oidcProviderRoutes = (config) => {
9996
10023
  return grantBackchannel(client, body, headers.dpop, clientCertThumbprint);
9997
10024
  }
9998
10025
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
9999
- }, {
10026
+ }).post(parRoute, {
10000
10027
  body: t15.Object({
10001
- assertion: t15.Optional(t15.String()),
10028
+ acr_values: t15.Optional(t15.String()),
10002
10029
  audience: t15.Optional(t15.String()),
10003
- auth_req_id: t15.Optional(t15.String()),
10004
- claim_token: t15.Optional(t15.String()),
10030
+ claims: t15.Optional(t15.String()),
10005
10031
  client_assertion: t15.Optional(t15.String()),
10006
10032
  client_assertion_type: t15.Optional(t15.String()),
10007
10033
  client_id: t15.Optional(t15.String()),
10008
10034
  client_secret: t15.Optional(t15.String()),
10009
- code: t15.Optional(t15.String()),
10010
- code_verifier: t15.Optional(t15.String()),
10011
- device_code: t15.Optional(t15.String()),
10012
- grant_type: t15.Optional(t15.String()),
10013
- "pre-authorized_code": t15.Optional(t15.String()),
10035
+ code_challenge: t15.Optional(t15.String()),
10036
+ code_challenge_method: t15.Optional(t15.String()),
10037
+ nonce: t15.Optional(t15.String()),
10014
10038
  redirect_uri: t15.Optional(t15.String()),
10015
- refresh_token: t15.Optional(t15.String()),
10016
10039
  resource: t15.Optional(t15.String()),
10040
+ response_type: t15.Optional(t15.String()),
10017
10041
  scope: t15.Optional(t15.String()),
10018
- subject_token: t15.Optional(t15.String()),
10019
- subject_token_type: t15.Optional(t15.String())
10042
+ state: t15.Optional(t15.String())
10043
+ }),
10044
+ headers: t15.Object({
10045
+ authorization: t15.Optional(t15.String())
10020
10046
  })
10021
- }).post(parRoute, async ({ body, headers, request }) => {
10047
+ }, async ({ body, headers, request }) => {
10022
10048
  if (config.pushedAuthorizationRequestStore === undefined) {
10023
10049
  return oauthError2(HTTP_NOT_IMPLEMENTED, "unsupported_response_type");
10024
10050
  }
@@ -10045,28 +10071,17 @@ var oidcProviderRoutes = (config) => {
10045
10071
  ttlMs: config.pushedAuthorizationRequestTtlMs
10046
10072
  });
10047
10073
  return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
10048
- }, {
10074
+ }).post(introspectRoute, {
10049
10075
  body: t15.Object({
10050
- acr_values: t15.Optional(t15.String()),
10051
- audience: t15.Optional(t15.String()),
10052
- claims: t15.Optional(t15.String()),
10053
- client_assertion: t15.Optional(t15.String()),
10054
- client_assertion_type: t15.Optional(t15.String()),
10055
10076
  client_id: t15.Optional(t15.String()),
10056
10077
  client_secret: t15.Optional(t15.String()),
10057
- code_challenge: t15.Optional(t15.String()),
10058
- code_challenge_method: t15.Optional(t15.String()),
10059
- nonce: t15.Optional(t15.String()),
10060
- redirect_uri: t15.Optional(t15.String()),
10061
- resource: t15.Optional(t15.String()),
10062
- response_type: t15.Optional(t15.String()),
10063
- scope: t15.Optional(t15.String()),
10064
- state: t15.Optional(t15.String())
10078
+ token: t15.String(),
10079
+ token_type_hint: t15.Optional(t15.String())
10065
10080
  }),
10066
10081
  headers: t15.Object({
10067
10082
  authorization: t15.Optional(t15.String())
10068
10083
  })
10069
- }).post(introspectRoute, async ({ body, headers }) => {
10084
+ }, async ({ body, headers }) => {
10070
10085
  const basic = readBasicAuth2(headers.authorization);
10071
10086
  const clientId = body.client_id ?? basic.clientId;
10072
10087
  const clientSecret = body.client_secret ?? basic.clientSecret;
@@ -10084,7 +10099,7 @@ var oidcProviderRoutes = (config) => {
10084
10099
  token: body.token
10085
10100
  });
10086
10101
  return jsonResponse(result, HTTP_OK3);
10087
- }, {
10102
+ }).post(revokeRoute, {
10088
10103
  body: t15.Object({
10089
10104
  client_id: t15.Optional(t15.String()),
10090
10105
  client_secret: t15.Optional(t15.String()),
@@ -10094,7 +10109,7 @@ var oidcProviderRoutes = (config) => {
10094
10109
  headers: t15.Object({
10095
10110
  authorization: t15.Optional(t15.String())
10096
10111
  })
10097
- }).post(revokeRoute, async ({ body, headers }) => {
10112
+ }, async ({ body, headers }) => {
10098
10113
  const basic = readBasicAuth2(headers.authorization);
10099
10114
  const clientId = body.client_id ?? basic.clientId;
10100
10115
  const clientSecret = body.client_secret ?? basic.clientSecret;
@@ -10109,17 +10124,18 @@ var oidcProviderRoutes = (config) => {
10109
10124
  await revokeRefreshToken(config, body.token);
10110
10125
  }
10111
10126
  return new Response(null, { status: HTTP_OK3 });
10112
- }, {
10127
+ }).post(backchannelAuthorizationRoute, {
10113
10128
  body: t15.Object({
10129
+ binding_message: t15.Optional(t15.String()),
10114
10130
  client_id: t15.Optional(t15.String()),
10115
10131
  client_secret: t15.Optional(t15.String()),
10116
- token: t15.String(),
10117
- token_type_hint: t15.Optional(t15.String())
10132
+ login_hint: t15.Optional(t15.String()),
10133
+ scope: t15.Optional(t15.String())
10118
10134
  }),
10119
10135
  headers: t15.Object({
10120
10136
  authorization: t15.Optional(t15.String())
10121
10137
  })
10122
- }).post(backchannelAuthorizationRoute, async ({ body, headers }) => {
10138
+ }, async ({ body, headers }) => {
10123
10139
  if (config.backchannelAuthStore === undefined) {
10124
10140
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
10125
10141
  }
@@ -10152,18 +10168,16 @@ var oidcProviderRoutes = (config) => {
10152
10168
  expires_in: result.expires_in,
10153
10169
  interval: result.interval
10154
10170
  }, HTTP_OK3);
10155
- }, {
10171
+ }).post(deviceAuthorizationRoute, {
10156
10172
  body: t15.Object({
10157
- binding_message: t15.Optional(t15.String()),
10158
10173
  client_id: t15.Optional(t15.String()),
10159
10174
  client_secret: t15.Optional(t15.String()),
10160
- login_hint: t15.Optional(t15.String()),
10161
10175
  scope: t15.Optional(t15.String())
10162
10176
  }),
10163
10177
  headers: t15.Object({
10164
10178
  authorization: t15.Optional(t15.String())
10165
10179
  })
10166
- }).post(deviceAuthorizationRoute, async ({ body, headers }) => {
10180
+ }, async ({ body, headers }) => {
10167
10181
  if (config.deviceAuthorizationStore === undefined) {
10168
10182
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
10169
10183
  }
@@ -10185,16 +10199,15 @@ var oidcProviderRoutes = (config) => {
10185
10199
  requestedScopes: requested
10186
10200
  });
10187
10201
  return jsonResponse(response, HTTP_OK3);
10188
- }, {
10202
+ }).post(deviceApproveRoute, {
10189
10203
  body: t15.Object({
10190
- client_id: t15.Optional(t15.String()),
10191
- client_secret: t15.Optional(t15.String()),
10192
- scope: t15.Optional(t15.String())
10204
+ action: t15.Optional(t15.Union([t15.Literal("approve"), t15.Literal("deny")])),
10205
+ user_code: t15.String()
10193
10206
  }),
10194
- headers: t15.Object({
10195
- authorization: t15.Optional(t15.String())
10207
+ cookie: t15.Cookie({
10208
+ user_session_id: t15.Optional(userSessionIdTypebox)
10196
10209
  })
10197
- }).post(deviceApproveRoute, async ({ body, cookie: { user_session_id }, store }) => {
10210
+ }, async ({ body, cookie: { user_session_id }, store }) => {
10198
10211
  if (config.deviceAuthorizationStore === undefined) {
10199
10212
  return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
10200
10213
  }
@@ -10217,19 +10230,7 @@ var oidcProviderRoutes = (config) => {
10217
10230
  if (!result.ok)
10218
10231
  return oauthError2(HTTP_BAD_REQUEST3, result.error);
10219
10232
  return jsonResponse({ ok: true }, HTTP_OK3);
10220
- }, {
10221
- body: t15.Object({
10222
- action: t15.Optional(t15.Union([t15.Literal("approve"), t15.Literal("deny")])),
10223
- user_code: t15.String()
10224
- }),
10225
- cookie: t15.Cookie({
10226
- user_session_id: t15.Optional(userSessionIdTypebox)
10227
- })
10228
- }).get(endSessionRoute, async ({ cookie: { user_session_id }, query, store }) => handleEndSession({
10229
- cookie: user_session_id,
10230
- inMemorySession: store.session,
10231
- query
10232
- }), {
10233
+ }).get(endSessionRoute, {
10233
10234
  cookie: t15.Cookie({
10234
10235
  user_session_id: t15.Optional(userSessionIdTypebox)
10235
10236
  }),
@@ -10239,11 +10240,11 @@ var oidcProviderRoutes = (config) => {
10239
10240
  post_logout_redirect_uri: t15.Optional(t15.String()),
10240
10241
  state: t15.Optional(t15.String())
10241
10242
  })
10242
- }).post(endSessionRoute, async ({ body, cookie: { user_session_id }, store }) => handleEndSession({
10243
+ }, async ({ cookie: { user_session_id }, query, store }) => handleEndSession({
10243
10244
  cookie: user_session_id,
10244
10245
  inMemorySession: store.session,
10245
- query: body
10246
- }), {
10246
+ query
10247
+ })).post(endSessionRoute, {
10247
10248
  body: t15.Object({
10248
10249
  client_id: t15.Optional(t15.String()),
10249
10250
  id_token_hint: t15.Optional(t15.String()),
@@ -10253,7 +10254,25 @@ var oidcProviderRoutes = (config) => {
10253
10254
  cookie: t15.Cookie({
10254
10255
  user_session_id: t15.Optional(userSessionIdTypebox)
10255
10256
  })
10256
- }).post(registrationRoute, async ({ body, headers }) => {
10257
+ }, async ({ body, cookie: { user_session_id }, store }) => handleEndSession({
10258
+ cookie: user_session_id,
10259
+ inMemorySession: store.session,
10260
+ query: body
10261
+ })).post(registrationRoute, {
10262
+ body: t15.Object({
10263
+ backchannel_logout_uri: t15.Optional(t15.String()),
10264
+ client_name: t15.Optional(t15.String()),
10265
+ grant_types: t15.Optional(t15.Array(t15.String())),
10266
+ jwks: t15.Optional(t15.Any()),
10267
+ jwks_uri: t15.Optional(t15.String()),
10268
+ post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
10269
+ redirect_uris: t15.Optional(t15.Array(t15.String())),
10270
+ scope: t15.Optional(t15.String())
10271
+ }),
10272
+ headers: t15.Object({
10273
+ authorization: t15.Optional(t15.String())
10274
+ })
10275
+ }, async ({ body, headers }) => {
10257
10276
  if (config.clientRegistrationTokenStore === undefined) {
10258
10277
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
10259
10278
  }
@@ -10269,21 +10288,12 @@ var oidcProviderRoutes = (config) => {
10269
10288
  registrationTokenStore: config.clientRegistrationTokenStore
10270
10289
  });
10271
10290
  return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
10272
- }, {
10273
- body: t15.Object({
10274
- backchannel_logout_uri: t15.Optional(t15.String()),
10275
- client_name: t15.Optional(t15.String()),
10276
- grant_types: t15.Optional(t15.Array(t15.String())),
10277
- jwks: t15.Optional(t15.Any()),
10278
- jwks_uri: t15.Optional(t15.String()),
10279
- post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
10280
- redirect_uris: t15.Optional(t15.Array(t15.String())),
10281
- scope: t15.Optional(t15.String())
10282
- }),
10291
+ }).get(`${registrationRoute}/:clientId`, {
10283
10292
  headers: t15.Object({
10284
10293
  authorization: t15.Optional(t15.String())
10285
- })
10286
- }).get(`${registrationRoute}/:clientId`, async ({ headers, params: { clientId } }) => {
10294
+ }),
10295
+ params: t15.Object({ clientId: t15.String() })
10296
+ }, async ({ headers, params: { clientId } }) => {
10287
10297
  if (config.clientRegistrationTokenStore === undefined) {
10288
10298
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
10289
10299
  }
@@ -10294,12 +10304,22 @@ var oidcProviderRoutes = (config) => {
10294
10304
  registrationTokenStore: config.clientRegistrationTokenStore
10295
10305
  });
10296
10306
  return jsonResponse(result.body, result.status);
10297
- }, {
10307
+ }).put(`${registrationRoute}/:clientId`, {
10308
+ body: t15.Object({
10309
+ backchannel_logout_uri: t15.Optional(t15.String()),
10310
+ client_name: t15.Optional(t15.String()),
10311
+ grant_types: t15.Optional(t15.Array(t15.String())),
10312
+ jwks: t15.Optional(t15.Any()),
10313
+ jwks_uri: t15.Optional(t15.String()),
10314
+ post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
10315
+ redirect_uris: t15.Optional(t15.Array(t15.String())),
10316
+ scope: t15.Optional(t15.String())
10317
+ }),
10298
10318
  headers: t15.Object({
10299
10319
  authorization: t15.Optional(t15.String())
10300
10320
  }),
10301
10321
  params: t15.Object({ clientId: t15.String() })
10302
- }).put(`${registrationRoute}/:clientId`, async ({ body, headers, params: { clientId } }) => {
10322
+ }, async ({ body, headers, params: { clientId } }) => {
10303
10323
  if (config.clientRegistrationTokenStore === undefined) {
10304
10324
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
10305
10325
  }
@@ -10312,22 +10332,12 @@ var oidcProviderRoutes = (config) => {
10312
10332
  registrationTokenStore: config.clientRegistrationTokenStore
10313
10333
  });
10314
10334
  return jsonResponse(result.body, result.status);
10315
- }, {
10316
- body: t15.Object({
10317
- backchannel_logout_uri: t15.Optional(t15.String()),
10318
- client_name: t15.Optional(t15.String()),
10319
- grant_types: t15.Optional(t15.Array(t15.String())),
10320
- jwks: t15.Optional(t15.Any()),
10321
- jwks_uri: t15.Optional(t15.String()),
10322
- post_logout_redirect_uris: t15.Optional(t15.Array(t15.String())),
10323
- redirect_uris: t15.Optional(t15.Array(t15.String())),
10324
- scope: t15.Optional(t15.String())
10325
- }),
10335
+ }).delete(`${registrationRoute}/:clientId`, {
10326
10336
  headers: t15.Object({
10327
10337
  authorization: t15.Optional(t15.String())
10328
10338
  }),
10329
10339
  params: t15.Object({ clientId: t15.String() })
10330
- }).delete(`${registrationRoute}/:clientId`, async ({ headers, params: { clientId } }) => {
10340
+ }, async ({ headers, params: { clientId } }) => {
10331
10341
  if (config.clientRegistrationTokenStore === undefined) {
10332
10342
  return jsonResponse({ error: "unsupported_response_type" }, HTTP_NOT_IMPLEMENTED);
10333
10343
  }
@@ -10341,12 +10351,11 @@ var oidcProviderRoutes = (config) => {
10341
10351
  return new Response(null, { status: HTTP_NO_CONTENT });
10342
10352
  }
10343
10353
  return jsonResponse(result.body, result.status);
10344
- }, {
10354
+ }).get(userinfoRoute, {
10345
10355
  headers: t15.Object({
10346
10356
  authorization: t15.Optional(t15.String())
10347
- }),
10348
- params: t15.Object({ clientId: t15.String() })
10349
- }).get(userinfoRoute, async ({ headers }) => {
10357
+ })
10358
+ }, async ({ headers }) => {
10350
10359
  const token = readUserInfoBearer(headers.authorization);
10351
10360
  const result = await fetchUserInfo({ config, token });
10352
10361
  if (!result.ok) {
@@ -10359,11 +10368,14 @@ var oidcProviderRoutes = (config) => {
10359
10368
  });
10360
10369
  }
10361
10370
  return jsonResponse(result.body, HTTP_OK3);
10362
- }, {
10371
+ }).post(userinfoRoute, {
10372
+ body: t15.Object({
10373
+ access_token: t15.Optional(t15.String())
10374
+ }),
10363
10375
  headers: t15.Object({
10364
10376
  authorization: t15.Optional(t15.String())
10365
10377
  })
10366
- }).post(userinfoRoute, async ({ headers, body }) => {
10378
+ }, async ({ headers, body }) => {
10367
10379
  const token = readUserInfoBearer(headers.authorization) ?? body.access_token;
10368
10380
  const result = await fetchUserInfo({ config, token });
10369
10381
  if (!result.ok) {
@@ -10376,13 +10388,6 @@ var oidcProviderRoutes = (config) => {
10376
10388
  });
10377
10389
  }
10378
10390
  return jsonResponse(result.body, HTTP_OK3);
10379
- }, {
10380
- body: t15.Object({
10381
- access_token: t15.Optional(t15.String())
10382
- }),
10383
- headers: t15.Object({
10384
- authorization: t15.Optional(t15.String())
10385
- })
10386
10391
  }).get(jwksRoute, () => ({
10387
10392
  keys: signingVerificationKeys(signingKey, config.previousSigningKeys).map(toPublicJwk)
10388
10393
  })).get("/.well-known/openid-configuration", () => discovery).get("/.well-known/oauth-authorization-server", () => discovery);
@@ -10521,7 +10526,7 @@ var organizationRoutes = ({
10521
10526
  }
10522
10527
  return membership?.status === "active";
10523
10528
  };
10524
- return new Elysia23().use(sessionStore()).get(organizationsRoute, async ({
10529
+ return new Elysia23().use(sessionStore()).get(organizationsRoute, { cookie }, async ({
10525
10530
  cookie: { user_session_id },
10526
10531
  status,
10527
10532
  store: { session }
@@ -10535,7 +10540,13 @@ var organizationRoutes = ({
10535
10540
  userId: getUserId(user)
10536
10541
  });
10537
10542
  return status("OK", { organizations });
10538
- }, { cookie }).post(organizationsRoute, async ({
10543
+ }).post(organizationsRoute, {
10544
+ body: t16.Object({
10545
+ metadata: t16.Optional(t16.Record(t16.String(), t16.Unknown())),
10546
+ name: t16.String()
10547
+ }),
10548
+ cookie
10549
+ }, async ({
10539
10550
  body: { metadata, name },
10540
10551
  cookie: { user_session_id },
10541
10552
  status,
@@ -10567,13 +10578,14 @@ var organizationRoutes = ({
10567
10578
  ownerUserId
10568
10579
  });
10569
10580
  return status("OK", { organization });
10570
- }, {
10581
+ }).post(`${organizationsRoute}/:organizationId/invitations`, {
10571
10582
  body: t16.Object({
10572
- metadata: t16.Optional(t16.Record(t16.String(), t16.Unknown())),
10573
- name: t16.String()
10583
+ email: t16.String(),
10584
+ roles: t16.Optional(t16.Array(t16.String()))
10574
10585
  }),
10575
- cookie
10576
- }).post(`${organizationsRoute}/:organizationId/invitations`, async ({
10586
+ cookie,
10587
+ params: t16.Object({ organizationId: t16.String() })
10588
+ }, async ({
10577
10589
  body: { email, roles },
10578
10590
  cookie: { user_session_id },
10579
10591
  params: { organizationId },
@@ -10613,14 +10625,7 @@ var organizationRoutes = ({
10613
10625
  invitationId: invitation.invitationId,
10614
10626
  token
10615
10627
  });
10616
- }, {
10617
- body: t16.Object({
10618
- email: t16.String(),
10619
- roles: t16.Optional(t16.Array(t16.String()))
10620
- }),
10621
- cookie,
10622
- params: t16.Object({ organizationId: t16.String() })
10623
- }).get(`${organizationsRoute}/:organizationId/invitations`, async ({
10628
+ }).get(`${organizationsRoute}/:organizationId/invitations`, { cookie, params: t16.Object({ organizationId: t16.String() }) }, async ({
10624
10629
  cookie: { user_session_id },
10625
10630
  params: { organizationId },
10626
10631
  status,
@@ -10643,7 +10648,13 @@ var organizationRoutes = ({
10643
10648
  state: invitation.state
10644
10649
  }))
10645
10650
  });
10646
- }, { cookie, params: t16.Object({ organizationId: t16.String() }) }).delete(`${organizationsRoute}/:organizationId/invitations/:invitationId`, async ({
10651
+ }).delete(`${organizationsRoute}/:organizationId/invitations/:invitationId`, {
10652
+ cookie,
10653
+ params: t16.Object({
10654
+ invitationId: t16.String(),
10655
+ organizationId: t16.String()
10656
+ })
10657
+ }, async ({
10647
10658
  cookie: { user_session_id },
10648
10659
  params: { invitationId, organizationId },
10649
10660
  status,
@@ -10665,13 +10676,7 @@ var organizationRoutes = ({
10665
10676
  state: "revoked"
10666
10677
  });
10667
10678
  return status("OK", { revoked: invitationId });
10668
- }, {
10669
- cookie,
10670
- params: t16.Object({
10671
- invitationId: t16.String(),
10672
- organizationId: t16.String()
10673
- })
10674
- }).post(`${organizationsRoute}/invitations/accept`, async ({
10679
+ }).post(`${organizationsRoute}/invitations/accept`, { body: t16.Object({ token: t16.String() }), cookie }, async ({
10675
10680
  body: { token },
10676
10681
  cookie: { user_session_id },
10677
10682
  status,
@@ -10704,7 +10709,7 @@ var organizationRoutes = ({
10704
10709
  organizationId: membership.organizationId,
10705
10710
  roles: membership.roles
10706
10711
  });
10707
- }, { body: t16.Object({ token: t16.String() }), cookie }).get(`${organizationsRoute}/:organizationId/members`, async ({
10712
+ }).get(`${organizationsRoute}/:organizationId/members`, { cookie, params: t16.Object({ organizationId: t16.String() }) }, async ({
10708
10713
  cookie: { user_session_id },
10709
10714
  params: { organizationId },
10710
10715
  status,
@@ -10720,7 +10725,13 @@ var organizationRoutes = ({
10720
10725
  }
10721
10726
  const members = await organizationStore.listMembershipsByOrganization(organizationId);
10722
10727
  return status("OK", { members });
10723
- }, { cookie, params: t16.Object({ organizationId: t16.String() }) }).delete(`${organizationsRoute}/:organizationId/members/:userId`, async ({
10728
+ }).delete(`${organizationsRoute}/:organizationId/members/:userId`, {
10729
+ cookie,
10730
+ params: t16.Object({
10731
+ organizationId: t16.String(),
10732
+ userId: t16.String()
10733
+ })
10734
+ }, async ({
10724
10735
  cookie: { user_session_id },
10725
10736
  params: { organizationId, userId },
10726
10737
  status,
@@ -10742,12 +10753,6 @@ var organizationRoutes = ({
10742
10753
  });
10743
10754
  await onMembershipRemoved?.({ organizationId, userId });
10744
10755
  return status("OK", { removed: userId });
10745
- }, {
10746
- cookie,
10747
- params: t16.Object({
10748
- organizationId: t16.String(),
10749
- userId: t16.String()
10750
- })
10751
10756
  });
10752
10757
  };
10753
10758
 
@@ -10814,7 +10819,7 @@ var passwordlessRoutes = ({
10814
10819
  await onPasswordlessLogin?.({ user, userSessionId });
10815
10820
  return userSessionId;
10816
10821
  };
10817
- const magicLink = onSendMagicLink ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, async ({ body: { email }, status }) => {
10822
+ const magicLink = onSendMagicLink ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, { body: t17.Object({ email: t17.String() }) }, async ({ body: { email }, status }) => {
10818
10823
  const normalizedEmail = email.trim().toLowerCase();
10819
10824
  const token = generateSecureToken();
10820
10825
  const expiresAt = Date.now() + magicLinkTokenDurationMs;
@@ -10829,7 +10834,7 @@ var passwordlessRoutes = ({
10829
10834
  token
10830
10835
  });
10831
10836
  return status("OK", { status: "magic_link_sent" });
10832
- }, { body: t17.Object({ email: t17.String() }) }).post(`${passwordlessRoute}/magic-link/verify`, async ({
10837
+ }).post(`${passwordlessRoute}/magic-link/verify`, { body: t17.Object({ token: t17.String() }), cookie }, async ({
10833
10838
  body: { token },
10834
10839
  cookie: { user_session_id },
10835
10840
  status,
@@ -10844,8 +10849,8 @@ var passwordlessRoutes = ({
10844
10849
  return status("Unauthorized", "No account for this email");
10845
10850
  }
10846
10851
  return status("OK", { status: "authenticated" });
10847
- }, { body: t17.Object({ token: t17.String() }), cookie }) : new Elysia24;
10848
- const otp = onSendOtp ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/otp`, async ({ body: { email }, status }) => {
10852
+ }) : new Elysia24;
10853
+ const otp = onSendOtp ? new Elysia24().use(sessionStore()).post(`${passwordlessRoute}/otp`, { body: t17.Object({ email: t17.String() }) }, async ({ body: { email }, status }) => {
10849
10854
  const normalizedEmail = email.trim().toLowerCase();
10850
10855
  const code = generateOtpCode(otpLength);
10851
10856
  const expiresAt = Date.now() + otpDurationMs;
@@ -10860,7 +10865,13 @@ var passwordlessRoutes = ({
10860
10865
  expiresAt
10861
10866
  });
10862
10867
  return status("OK", { status: "otp_sent" });
10863
- }, { body: t17.Object({ email: t17.String() }) }).post(`${passwordlessRoute}/otp/verify`, async ({
10868
+ }).post(`${passwordlessRoute}/otp/verify`, {
10869
+ body: t17.Object({
10870
+ code: t17.String(),
10871
+ email: t17.String()
10872
+ }),
10873
+ cookie
10874
+ }, async ({
10864
10875
  body: { code, email },
10865
10876
  cookie: { user_session_id },
10866
10877
  status,
@@ -10876,12 +10887,6 @@ var passwordlessRoutes = ({
10876
10887
  return status("Unauthorized", "No account for this email");
10877
10888
  }
10878
10889
  return status("OK", { status: "authenticated" });
10879
- }, {
10880
- body: t17.Object({
10881
- code: t17.String(),
10882
- email: t17.String()
10883
- }),
10884
- cookie
10885
10890
  }) : new Elysia24;
10886
10891
  return new Elysia24().use(magicLink).use(otp);
10887
10892
  };
@@ -11005,7 +11010,14 @@ var portalRoutes = ({
11005
11010
  } : undefined,
11006
11011
  scim: capabilities.includes("scim") ? { baseUrl: `${origin}${scimRoute}` } : undefined
11007
11012
  });
11008
- }).put(`${portalRoute}/connection/saml`, async ({ body, headers, status }) => {
11013
+ }).put(`${portalRoute}/connection/saml`, {
11014
+ body: t18.Object({
11015
+ idpEntityId: t18.String(),
11016
+ idpSloUrl: t18.Optional(t18.String()),
11017
+ idpSsoUrl: t18.String(),
11018
+ idpX509Cert: t18.String()
11019
+ })
11020
+ }, async ({ body, headers, status }) => {
11009
11021
  const session = await loadSession(headers.authorization);
11010
11022
  if (!session) {
11011
11023
  return status("Unauthorized", "Invalid or expired setup link");
@@ -11044,14 +11056,15 @@ var portalRoutes = ({
11044
11056
  type: "saml"
11045
11057
  });
11046
11058
  return status("OK", { configured: true, type: "saml" });
11047
- }, {
11059
+ }).put(`${portalRoute}/connection/oidc`, {
11048
11060
  body: t18.Object({
11049
- idpEntityId: t18.String(),
11050
- idpSloUrl: t18.Optional(t18.String()),
11051
- idpSsoUrl: t18.String(),
11052
- idpX509Cert: t18.String()
11061
+ clientId: t18.String(),
11062
+ clientSecret: t18.String(),
11063
+ issuer: t18.String(),
11064
+ redirectUri: t18.Optional(t18.String()),
11065
+ scopes: t18.Optional(t18.Array(t18.String()))
11053
11066
  })
11054
- }).put(`${portalRoute}/connection/oidc`, async ({ body, headers, request, status }) => {
11067
+ }, async ({ body, headers, request, status }) => {
11055
11068
  const session = await loadSession(headers.authorization);
11056
11069
  if (!session) {
11057
11070
  return status("Unauthorized", "Invalid or expired setup link");
@@ -11092,14 +11105,6 @@ var portalRoutes = ({
11092
11105
  type: "oidc"
11093
11106
  });
11094
11107
  return status("OK", { configured: true, type: "oidc" });
11095
- }, {
11096
- body: t18.Object({
11097
- clientId: t18.String(),
11098
- clientSecret: t18.String(),
11099
- issuer: t18.String(),
11100
- redirectUri: t18.Optional(t18.String()),
11101
- scopes: t18.Optional(t18.Array(t18.String()))
11102
- })
11103
11108
  }).post(`${portalRoute}/scim/token`, async ({ headers, request, status }) => {
11104
11109
  const session = await loadSession(headers.authorization);
11105
11110
  if (!session) {
@@ -11180,7 +11185,7 @@ var roleRoutes = ({
11180
11185
  }
11181
11186
  return membership?.status === "active";
11182
11187
  };
11183
- return new Elysia26().use(sessionStore()).get(`${rolesRoute}/:organizationId`, async ({
11188
+ return new Elysia26().use(sessionStore()).get(`${rolesRoute}/:organizationId`, { cookie, params: t19.Object({ organizationId: t19.String() }) }, async ({
11184
11189
  cookie: { user_session_id },
11185
11190
  params: { organizationId },
11186
11191
  status,
@@ -11198,7 +11203,14 @@ var roleRoutes = ({
11198
11203
  roleStore.listRoles()
11199
11204
  ]);
11200
11205
  return status("OK", { roles: [...scoped, ...global2] });
11201
- }, { cookie, params: t19.Object({ organizationId: t19.String() }) }).put(`${rolesRoute}/:organizationId/members/:userId`, async ({
11206
+ }).put(`${rolesRoute}/:organizationId/members/:userId`, {
11207
+ body: t19.Object({ roles: t19.Array(t19.String()) }),
11208
+ cookie,
11209
+ params: t19.Object({
11210
+ organizationId: t19.String(),
11211
+ userId: t19.String()
11212
+ })
11213
+ }, async ({
11202
11214
  body: { roles },
11203
11215
  cookie: { user_session_id },
11204
11216
  params: { organizationId, userId },
@@ -11230,13 +11242,6 @@ var roleRoutes = ({
11230
11242
  });
11231
11243
  await onRolesAssigned?.({ organizationId, roles, userId });
11232
11244
  return status("OK", { roles: updated.roles });
11233
- }, {
11234
- body: t19.Object({ roles: t19.Array(t19.String()) }),
11235
- cookie,
11236
- params: t19.Object({
11237
- organizationId: t19.String(),
11238
- userId: t19.String()
11239
- })
11240
11245
  });
11241
11246
  };
11242
11247
 
@@ -11428,7 +11433,20 @@ var authorize = ({
11428
11433
  onAuthorizeError
11429
11434
  }) => {
11430
11435
  const secure = resolveCookieSecure(cookieSecure);
11431
- return new Elysia27().get(authorizeRoute, async ({
11436
+ return new Elysia27().get(authorizeRoute, {
11437
+ cookie: t20.Cookie({
11438
+ auth_client: authClientOption,
11439
+ auth_intent: authIntentOption,
11440
+ auth_provider: t20.Optional(authProviderOption)
11441
+ }),
11442
+ params: t20.Object({
11443
+ provider: authProviderOption
11444
+ }),
11445
+ query: t20.Object({
11446
+ client: authClientOption,
11447
+ intent: authIntentOption
11448
+ })
11449
+ }, async ({
11432
11450
  status,
11433
11451
  redirect,
11434
11452
  cookie: {
@@ -11544,19 +11562,6 @@ var authorize = ({
11544
11562
  });
11545
11563
  return status("Internal Server Error", "Failed to create authorization URL");
11546
11564
  }
11547
- }, {
11548
- cookie: t20.Cookie({
11549
- auth_client: authClientOption,
11550
- auth_intent: authIntentOption,
11551
- auth_provider: t20.Optional(authProviderOption)
11552
- }),
11553
- params: t20.Object({
11554
- provider: authProviderOption
11555
- }),
11556
- query: t20.Object({
11557
- client: authClientOption,
11558
- intent: authIntentOption
11559
- })
11560
11565
  });
11561
11566
  };
11562
11567
 
@@ -11584,7 +11589,17 @@ var callback = ({
11584
11589
  onLinkIdentityConflict,
11585
11590
  onLinkConnector,
11586
11591
  onCallbackError
11587
- }) => new Elysia28().use(sessionStore()).get(callbackRoute, async ({
11592
+ }) => new Elysia28().use(sessionStore()).get(callbackRoute, {
11593
+ cookie: t21.Cookie({
11594
+ auth_client: authClientOption,
11595
+ auth_intent: authIntentOption,
11596
+ auth_provider: t21.Optional(authProviderOption),
11597
+ code_verifier: t21.Optional(t21.String()),
11598
+ origin_url: t21.Optional(t21.String()),
11599
+ state: t21.Optional(t21.String()),
11600
+ user_session_id: t21.Optional(userSessionIdTypebox)
11601
+ })
11602
+ }, async ({
11588
11603
  status,
11589
11604
  redirect,
11590
11605
  store: { session, unregisteredSession },
@@ -11718,17 +11733,7 @@ var callback = ({
11718
11733
  return response;
11719
11734
  }
11720
11735
  return redirect(originUrl);
11721
- }), {
11722
- cookie: t21.Cookie({
11723
- auth_client: authClientOption,
11724
- auth_intent: authIntentOption,
11725
- auth_provider: t21.Optional(authProviderOption),
11726
- code_verifier: t21.Optional(t21.String()),
11727
- origin_url: t21.Optional(t21.String()),
11728
- state: t21.Optional(t21.String()),
11729
- user_session_id: t21.Optional(userSessionIdTypebox)
11730
- })
11731
- });
11736
+ }));
11732
11737
 
11733
11738
  // src/routes/profile.ts
11734
11739
  import { Elysia as Elysia29, t as t22 } from "elysia";
@@ -11738,7 +11743,13 @@ var profile = ({
11738
11743
  profileRoute = "/oauth2/profile",
11739
11744
  onProfileSuccess,
11740
11745
  onProfileError
11741
- }) => new Elysia29().use(sessionStore()).get(profileRoute, async ({
11746
+ }) => new Elysia29().use(sessionStore()).get(profileRoute, {
11747
+ cookie: t22.Cookie({
11748
+ auth_client: authClientOption,
11749
+ auth_provider: authProviderOption,
11750
+ user_session_id: userSessionIdTypebox
11751
+ })
11752
+ }, async ({
11742
11753
  status,
11743
11754
  store: { session },
11744
11755
  cookie: { user_session_id, auth_provider, auth_client }
@@ -11791,12 +11802,6 @@ var profile = ({
11791
11802
  });
11792
11803
  return err instanceof Error ? status("Internal Server Error", `${err.message} - ${err.stack ?? ""}`) : status("Internal Server Error", `Failed to validate authorization code: Unknown status: ${err}`);
11793
11804
  }
11794
- }, {
11795
- cookie: t22.Cookie({
11796
- auth_client: authClientOption,
11797
- auth_provider: authProviderOption,
11798
- user_session_id: userSessionIdTypebox
11799
- })
11800
11805
  });
11801
11806
 
11802
11807
  // src/routes/refresh.ts
@@ -11809,7 +11814,13 @@ var refresh = ({
11809
11814
  onRefreshSuccess,
11810
11815
  onRefreshError,
11811
11816
  sessionDurationMs = MILLISECONDS_IN_A_DAY
11812
- }) => new Elysia30().use(sessionStore()).post(refreshRoute, async ({
11817
+ }) => new Elysia30().use(sessionStore()).post(refreshRoute, {
11818
+ cookie: t23.Cookie({
11819
+ auth_client: authClientOption,
11820
+ auth_provider: authProviderOption,
11821
+ user_session_id: userSessionIdTypebox
11822
+ })
11823
+ }, async ({
11813
11824
  status,
11814
11825
  store: { session },
11815
11826
  cookie: { user_session_id, auth_provider, auth_client }
@@ -11874,12 +11885,6 @@ var refresh = ({
11874
11885
  });
11875
11886
  return status("Internal Server Error", "Failed to refresh token");
11876
11887
  }
11877
- }, {
11878
- cookie: t23.Cookie({
11879
- auth_client: authClientOption,
11880
- auth_provider: authProviderOption,
11881
- user_session_id: userSessionIdTypebox
11882
- })
11883
11888
  });
11884
11889
 
11885
11890
  // src/routes/revoke.ts
@@ -11890,7 +11895,13 @@ var revoke = ({
11890
11895
  revokeRoute = "/oauth2/revocation",
11891
11896
  onRevocationSuccess,
11892
11897
  onRevocationError
11893
- }) => new Elysia31().use(sessionStore()).post(revokeRoute, async ({
11898
+ }) => new Elysia31().use(sessionStore()).post(revokeRoute, {
11899
+ cookie: t24.Cookie({
11900
+ auth_client: authClientOption,
11901
+ auth_provider: authProviderOption,
11902
+ user_session_id: userSessionIdTypebox
11903
+ })
11904
+ }, async ({
11894
11905
  status,
11895
11906
  store: { session },
11896
11907
  cookie: { user_session_id, auth_provider, auth_client }
@@ -11956,12 +11967,6 @@ var revoke = ({
11956
11967
  });
11957
11968
  return status("Internal Server Error", "Failed to revoke token");
11958
11969
  }
11959
- }, {
11960
- cookie: t24.Cookie({
11961
- auth_client: authClientOption,
11962
- auth_provider: authProviderOption,
11963
- user_session_id: userSessionIdTypebox
11964
- })
11965
11970
  });
11966
11971
 
11967
11972
  // src/routes/sessions.ts
@@ -11970,7 +11975,7 @@ var sessionRoutes = ({
11970
11975
  authSessionStore,
11971
11976
  getUserId,
11972
11977
  sessionsRoute = "/auth/sessions"
11973
- }) => new Elysia32().use(sessionStore()).get(sessionsRoute, async ({
11978
+ }) => new Elysia32().use(sessionStore()).get(sessionsRoute, { cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
11974
11979
  cookie: { user_session_id },
11975
11980
  status,
11976
11981
  store: { session }
@@ -11998,7 +12003,10 @@ var sessionRoutes = ({
11998
12003
  id: entry.id
11999
12004
  }));
12000
12005
  return status("OK", { sessions: list });
12001
- }, { cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }).delete(`${sessionsRoute}/:id`, async ({
12006
+ }).delete(`${sessionsRoute}/:id`, {
12007
+ cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }),
12008
+ params: t25.Object({ id: t25.String() })
12009
+ }, async ({
12002
12010
  cookie: { user_session_id },
12003
12011
  params: { id },
12004
12012
  status,
@@ -12024,9 +12032,6 @@ var sessionRoutes = ({
12024
12032
  }
12025
12033
  await authSessionStore.removeSession(id);
12026
12034
  return status("OK", { revoked: id });
12027
- }, {
12028
- cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }),
12029
- params: t25.Object({ id: t25.String() })
12030
12035
  });
12031
12036
 
12032
12037
  // src/routes/signout.ts
@@ -12060,7 +12065,12 @@ var signout = ({
12060
12065
  authSessionStore,
12061
12066
  signoutRoute = "/oauth2/signout",
12062
12067
  onSignOut
12063
- }) => new Elysia33().use(sessionStore()).delete(signoutRoute, async ({
12068
+ }) => new Elysia33().use(sessionStore()).delete(signoutRoute, {
12069
+ cookie: t26.Cookie({
12070
+ auth_provider: t26.Optional(authProviderOption),
12071
+ user_session_id: t26.Optional(t26.TemplateLiteral("${string}-${string}-${string}-${string}-${string}"))
12072
+ })
12073
+ }, async ({
12064
12074
  status,
12065
12075
  store: { session },
12066
12076
  cookie: { user_session_id, auth_provider }
@@ -12099,12 +12109,7 @@ var signout = ({
12099
12109
  user_session_id.remove();
12100
12110
  auth_provider?.remove();
12101
12111
  return new Response(null, { status: 204 });
12102
- }), {
12103
- cookie: t26.Cookie({
12104
- auth_provider: t26.Optional(authProviderOption),
12105
- user_session_id: t26.Optional(t26.TemplateLiteral("${string}-${string}-${string}-${string}-${string}"))
12106
- })
12107
- });
12112
+ }));
12108
12113
 
12109
12114
  // src/routes/userStatus.ts
12110
12115
  import { Elysia as Elysia34, t as t27 } from "elysia";
@@ -12112,7 +12117,11 @@ var userStatus = ({
12112
12117
  authSessionStore,
12113
12118
  statusRoute = "/oauth2/status",
12114
12119
  onStatus
12115
- }) => new Elysia34().use(sessionStore()).get(statusRoute, async ({ status, cookie: { user_session_id }, store: { session } }) => {
12120
+ }) => new Elysia34().use(sessionStore()).get(statusRoute, { cookie: t27.Cookie({ user_session_id: userSessionIdTypebox }) }, async ({
12121
+ status,
12122
+ cookie: { user_session_id },
12123
+ store: { session }
12124
+ }) => {
12116
12125
  const { user, impersonator, error } = await getStatusFromSource({
12117
12126
  authSessionStore,
12118
12127
  session,
@@ -12127,7 +12136,7 @@ var userStatus = ({
12127
12136
  return err instanceof Error ? status("Internal Server Error", `Error: ${err.message} - ${err.stack ?? ""}`) : status("Internal Server Error", `Unknown Error: ${String(err)}`);
12128
12137
  }
12129
12138
  return { impersonator, user };
12130
- }, { cookie: t27.Cookie({ user_session_id: userSessionIdTypebox }) });
12139
+ });
12131
12140
 
12132
12141
  // src/scim/routes.ts
12133
12142
  import { Elysia as Elysia35, t as t28 } from "elysia";
@@ -12603,7 +12612,7 @@ var scimRoutes = ({
12603
12612
  const resourceTypesLocation = (requestUrl) => `${new URL(requestUrl).origin}${scimRoute}/ResourceTypes`;
12604
12613
  const usersEndpoint = `${scimRoute}/Users`;
12605
12614
  const groupsEndpoint = `${scimRoute}/Groups`;
12606
- return new Elysia35().onParse(({ request }, contentType) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
12615
+ return new Elysia35().parse(({ contentType, request }) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
12607
12616
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12608
12617
  if (organizationId === undefined)
12609
12618
  return unauthorized();
@@ -12618,7 +12627,7 @@ var scimRoutes = ({
12618
12627
  }
12619
12628
  const user = await onScimUserCreate({ input, organizationId });
12620
12629
  return scimJson(toUserResource(user, userLocation(request.url, user.id), customAttributes), SCIM_CREATED);
12621
- }).get(usersRoute, async ({ headers, query, request }) => {
12630
+ }).get(usersRoute, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }, async ({ headers, query, request }) => {
12622
12631
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12623
12632
  if (organizationId === undefined)
12624
12633
  return unauthorized();
@@ -12628,7 +12637,7 @@ var scimRoutes = ({
12628
12637
  });
12629
12638
  const resources = users.map((user) => toUserResource(user, userLocation(request.url, user.id), customAttributes));
12630
12639
  return scimJson(listResponse(resources), SCIM_OK);
12631
- }, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }).get(userRoute, async ({ headers, params: { id }, request }) => {
12640
+ }).get(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
12632
12641
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12633
12642
  if (organizationId === undefined)
12634
12643
  return unauthorized();
@@ -12637,7 +12646,7 @@ var scimRoutes = ({
12637
12646
  return scimError(SCIM_NOT_FOUND, "User not found");
12638
12647
  }
12639
12648
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
12640
- }, { params: t28.Object({ id: t28.String() }) }).put(userRoute, async ({ body, headers, params: { id }, request }) => {
12649
+ }).put(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
12641
12650
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12642
12651
  if (organizationId === undefined)
12643
12652
  return unauthorized();
@@ -12654,7 +12663,7 @@ var scimRoutes = ({
12654
12663
  return scimError(SCIM_NOT_FOUND, "User not found");
12655
12664
  }
12656
12665
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
12657
- }, { params: t28.Object({ id: t28.String() }) }).patch(userRoute, async ({ body, headers, params: { id }, request }) => {
12666
+ }).patch(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
12658
12667
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12659
12668
  if (organizationId === undefined)
12660
12669
  return unauthorized();
@@ -12671,13 +12680,13 @@ var scimRoutes = ({
12671
12680
  return scimError(SCIM_NOT_FOUND, "User not found");
12672
12681
  }
12673
12682
  return scimJson(toUserResource(user, userLocation(request.url, id), customAttributes), SCIM_OK);
12674
- }, { params: t28.Object({ id: t28.String() }) }).delete(userRoute, async ({ headers, params: { id } }) => {
12683
+ }).delete(userRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id } }) => {
12675
12684
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12676
12685
  if (organizationId === undefined)
12677
12686
  return unauthorized();
12678
12687
  await onScimUserDeactivate({ id, organizationId });
12679
12688
  return new Response(null, { status: SCIM_NO_CONTENT });
12680
- }, { params: t28.Object({ id: t28.String() }) }).post(groupsRoute, async ({ body, headers, request }) => {
12689
+ }).post(groupsRoute, async ({ body, headers, request }) => {
12681
12690
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12682
12691
  if (organizationId === undefined)
12683
12692
  return unauthorized();
@@ -12692,7 +12701,7 @@ var scimRoutes = ({
12692
12701
  organizationId
12693
12702
  });
12694
12703
  return scimJson(toGroupResource(group, groupLocation(request.url, group.id)), SCIM_CREATED);
12695
- }).get(groupsRoute, async ({ headers, query, request }) => {
12704
+ }).get(groupsRoute, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }, async ({ headers, query, request }) => {
12696
12705
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12697
12706
  if (organizationId === undefined)
12698
12707
  return unauthorized();
@@ -12704,7 +12713,7 @@ var scimRoutes = ({
12704
12713
  });
12705
12714
  const resources = groups.map((group) => toGroupResource(group, groupLocation(request.url, group.id)));
12706
12715
  return scimJson(listResponse(resources), SCIM_OK);
12707
- }, { query: t28.Object({ filter: t28.Optional(t28.String()) }) }).get(groupRoute, async ({ headers, params: { id }, request }) => {
12716
+ }).get(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
12708
12717
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12709
12718
  if (organizationId === undefined)
12710
12719
  return unauthorized();
@@ -12715,7 +12724,7 @@ var scimRoutes = ({
12715
12724
  return scimError(SCIM_NOT_FOUND, "Group not found");
12716
12725
  }
12717
12726
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
12718
- }, { params: t28.Object({ id: t28.String() }) }).put(groupRoute, async ({ body, headers, params: { id }, request }) => {
12727
+ }).put(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
12719
12728
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12720
12729
  if (organizationId === undefined)
12721
12730
  return unauthorized();
@@ -12734,7 +12743,7 @@ var scimRoutes = ({
12734
12743
  return scimError(SCIM_NOT_FOUND, "Group not found");
12735
12744
  }
12736
12745
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
12737
- }, { params: t28.Object({ id: t28.String() }) }).patch(groupRoute, async ({ body, headers, params: { id }, request }) => {
12746
+ }).patch(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ body, headers, params: { id }, request }) => {
12738
12747
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12739
12748
  if (organizationId === undefined)
12740
12749
  return unauthorized();
@@ -12754,7 +12763,7 @@ var scimRoutes = ({
12754
12763
  return scimError(SCIM_NOT_FOUND, "Group not found");
12755
12764
  }
12756
12765
  return scimJson(toGroupResource(group, groupLocation(request.url, id)), SCIM_OK);
12757
- }, { params: t28.Object({ id: t28.String() }) }).delete(groupRoute, async ({ headers, params: { id } }) => {
12766
+ }).delete(groupRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id } }) => {
12758
12767
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12759
12768
  if (organizationId === undefined)
12760
12769
  return unauthorized();
@@ -12762,12 +12771,12 @@ var scimRoutes = ({
12762
12771
  return notImplemented();
12763
12772
  await onScimGroupDelete({ id, organizationId });
12764
12773
  return new Response(null, { status: SCIM_NO_CONTENT });
12765
- }, { params: t28.Object({ id: t28.String() }) }).get(schemasRoute, async ({ headers, request }) => {
12774
+ }).get(schemasRoute, async ({ headers, request }) => {
12766
12775
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12767
12776
  if (organizationId === undefined)
12768
12777
  return unauthorized();
12769
12778
  return scimJson(schemaList(schemasLocation(request.url), extensionSchemas), SCIM_OK);
12770
- }).get(schemaRoute, async ({ headers, params: { id }, request }) => {
12779
+ }).get(schemaRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
12771
12780
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12772
12781
  if (organizationId === undefined)
12773
12782
  return unauthorized();
@@ -12776,12 +12785,12 @@ var scimRoutes = ({
12776
12785
  return scimError(SCIM_NOT_FOUND, "Schema not found");
12777
12786
  }
12778
12787
  return scimJson(schema, SCIM_OK);
12779
- }, { params: t28.Object({ id: t28.String() }) }).get(resourceTypesRoute, async ({ headers, request }) => {
12788
+ }).get(resourceTypesRoute, async ({ headers, request }) => {
12780
12789
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12781
12790
  if (organizationId === undefined)
12782
12791
  return unauthorized();
12783
12792
  return scimJson(resourceTypeList(resourceTypesLocation(request.url), usersEndpoint, groupsEndpoint, extensionSchemas), SCIM_OK);
12784
- }).get(resourceTypeRoute, async ({ headers, params: { id }, request }) => {
12793
+ }).get(resourceTypeRoute, { params: t28.Object({ id: t28.String() }) }, async ({ headers, params: { id }, request }) => {
12785
12794
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
12786
12795
  if (organizationId === undefined)
12787
12796
  return unauthorized();
@@ -12790,7 +12799,7 @@ var scimRoutes = ({
12790
12799
  return scimError(SCIM_NOT_FOUND, "ResourceType not found");
12791
12800
  }
12792
12801
  return scimJson(resourceType, SCIM_OK);
12793
- }, { params: t28.Object({ id: t28.String() }) });
12802
+ });
12794
12803
  };
12795
12804
 
12796
12805
  // src/session/cleanup.ts
@@ -12803,17 +12812,19 @@ var sessionCleanup = ({
12803
12812
  onSessionCleanup
12804
12813
  }) => {
12805
12814
  let intervalId = null;
12806
- return new Elysia36({ name: "sessionCleanup" }).use(sessionStore()).onStart(({ store: { session, unregisteredSession } }) => {
12815
+ const sessionState = {};
12816
+ const unregisteredSessionState = {};
12817
+ return new Elysia36({ name: "sessionCleanup" }).use(sessionStore(sessionState, unregisteredSessionState)).setup(() => {
12807
12818
  intervalId = setInterval(async () => {
12808
12819
  await performCleanup({
12809
12820
  authSessionStore,
12810
12821
  maxSessions,
12811
12822
  onSessionCleanup,
12812
- session,
12813
- unregisteredSession
12823
+ session: sessionState,
12824
+ unregisteredSession: unregisteredSessionState
12814
12825
  });
12815
12826
  }, cleanupIntervalMs);
12816
- }).onStop(() => {
12827
+ }).cleanup(() => {
12817
12828
  if (intervalId) {
12818
12829
  clearInterval(intervalId);
12819
12830
  intervalId = null;
@@ -13049,7 +13060,7 @@ var ssoDiscoveryRoute = ({
13049
13060
  ssoRoute = DEFAULT_SSO_ROUTE
13050
13061
  }) => {
13051
13062
  const discoveryRoute = `${ssoRoute}/authorize`;
13052
- return new Elysia37().get(discoveryRoute, async ({ query: { email }, redirect, status }) => {
13063
+ return new Elysia37().get(discoveryRoute, { query: t29.Object({ email: t29.Optional(t29.String()) }) }, async ({ query: { email }, redirect, status }) => {
13053
13064
  if (!isNonEmptyString(email)) {
13054
13065
  return status("Bad Request", 'An "email" query parameter is required');
13055
13066
  }
@@ -13066,7 +13077,7 @@ var ssoDiscoveryRoute = ({
13066
13077
  return status("Not Found", "No SSO connection is configured for this organization");
13067
13078
  }
13068
13079
  return redirect(`${ssoRoute}/${connection.type}/${organizationId}/authorize`);
13069
- }, { query: t29.Object({ email: t29.Optional(t29.String()) }) });
13080
+ });
13070
13081
  };
13071
13082
 
13072
13083
  // src/sso/oidcRoutes.ts
@@ -13110,7 +13121,10 @@ var oidcSsoRoutes = ({
13110
13121
  const ssoCookieOptions = makeSsoCookieOptions(resolveCookieSecure(cookieSecure));
13111
13122
  const authorizeRoute = `${ssoRoute}/oidc/:organizationId/authorize`;
13112
13123
  const callbackRoute = `${ssoRoute}/oidc/:organizationId/callback`;
13113
- return new Elysia38().use(sessionStore()).get(authorizeRoute, async ({
13124
+ return new Elysia38().use(sessionStore()).get(authorizeRoute, {
13125
+ cookie: ssoCookieSchema,
13126
+ params: t30.Object({ organizationId: t30.String() })
13127
+ }, async ({
13114
13128
  cookie: {
13115
13129
  sso_nonce,
13116
13130
  sso_organization,
@@ -13148,10 +13162,14 @@ var oidcSsoRoutes = ({
13148
13162
  state
13149
13163
  });
13150
13164
  return redirect(authorizationUrl.toString());
13151
- }, {
13165
+ }).get(callbackRoute, {
13152
13166
  cookie: ssoCookieSchema,
13153
- params: t30.Object({ organizationId: t30.String() })
13154
- }).get(callbackRoute, async ({
13167
+ params: t30.Object({ organizationId: t30.String() }),
13168
+ query: t30.Object({
13169
+ code: t30.Optional(t30.String()),
13170
+ state: t30.Optional(t30.String())
13171
+ })
13172
+ }, async ({
13155
13173
  cookie: {
13156
13174
  sso_nonce,
13157
13175
  sso_organization,
@@ -13225,13 +13243,6 @@ var oidcSsoRoutes = ({
13225
13243
  await onSsoCallbackError?.({ error, organizationId });
13226
13244
  return status("Internal Server Error", "OIDC sign-in failed");
13227
13245
  }
13228
- }, {
13229
- cookie: ssoCookieSchema,
13230
- params: t30.Object({ organizationId: t30.String() }),
13231
- query: t30.Object({
13232
- code: t30.Optional(t30.String()),
13233
- state: t30.Optional(t30.String())
13234
- })
13235
13246
  });
13236
13247
  };
13237
13248
 
@@ -13281,7 +13292,7 @@ var samlSsoRoutes = ({
13281
13292
  const target = authSessionStore ? compatibilityLayer.session : inMemorySession;
13282
13293
  return target[userSessionId]?.samlLogout;
13283
13294
  };
13284
- return new Elysia39().use(sessionStore()).get(authorizeRoute, async ({
13295
+ return new Elysia39().use(sessionStore()).get(authorizeRoute, { params: t31.Object({ organizationId: t31.String() }) }, async ({
13285
13296
  headers,
13286
13297
  params: { organizationId },
13287
13298
  redirect,
@@ -13298,7 +13309,16 @@ var samlSsoRoutes = ({
13298
13309
  relayState: refererPath(headers["referer"])
13299
13310
  });
13300
13311
  return redirect(url);
13301
- }, { params: t31.Object({ organizationId: t31.String() }) }).post(acsRoute, async ({
13312
+ }).post(acsRoute, {
13313
+ body: t31.Object({
13314
+ RelayState: t31.Optional(t31.String()),
13315
+ SAMLResponse: t31.String()
13316
+ }),
13317
+ cookie: t31.Cookie({
13318
+ user_session_id: t31.Optional(userSessionIdTypebox)
13319
+ }),
13320
+ params: t31.Object({ organizationId: t31.String() })
13321
+ }, async ({
13302
13322
  body,
13303
13323
  cookie: { user_session_id },
13304
13324
  params: { organizationId },
@@ -13351,16 +13371,7 @@ var samlSsoRoutes = ({
13351
13371
  await onSsoCallbackError?.({ error, organizationId });
13352
13372
  return status("Internal Server Error", "SAML sign-in failed");
13353
13373
  }
13354
- }, {
13355
- body: t31.Object({
13356
- RelayState: t31.Optional(t31.String()),
13357
- SAMLResponse: t31.String()
13358
- }),
13359
- cookie: t31.Cookie({
13360
- user_session_id: t31.Optional(userSessionIdTypebox)
13361
- }),
13362
- params: t31.Object({ organizationId: t31.String() })
13363
- }).get(metadataRoute, async ({ params: { organizationId }, request, status }) => {
13374
+ }).get(metadataRoute, { params: t31.Object({ organizationId: t31.String() }) }, async ({ params: { organizationId }, request, status }) => {
13364
13375
  const connection = await ssoConnectionStore.getConnectionByOrganization(organizationId, "saml");
13365
13376
  if (connection === undefined || connection.type !== "saml") {
13366
13377
  return status("Not Found", "No SAML connection is configured for this organization");
@@ -13373,7 +13384,12 @@ var samlSsoRoutes = ({
13373
13384
  return new Response(metadata, {
13374
13385
  headers: { "content-type": "application/xml" }
13375
13386
  });
13376
- }, { params: t31.Object({ organizationId: t31.String() }) }).get(logoutRoute, async ({
13387
+ }).get(logoutRoute, {
13388
+ cookie: t31.Cookie({
13389
+ user_session_id: t31.Optional(userSessionIdTypebox)
13390
+ }),
13391
+ params: t31.Object({ organizationId: t31.String() })
13392
+ }, async ({
13377
13393
  cookie: { user_session_id },
13378
13394
  params: { organizationId },
13379
13395
  redirect,
@@ -13400,12 +13416,19 @@ var samlSsoRoutes = ({
13400
13416
  return redirect(url);
13401
13417
  }
13402
13418
  return redirect(idpSloUrl ?? "/");
13403
- }, {
13419
+ }).get(sloRoute, {
13404
13420
  cookie: t31.Cookie({
13405
13421
  user_session_id: t31.Optional(userSessionIdTypebox)
13406
13422
  }),
13407
- params: t31.Object({ organizationId: t31.String() })
13408
- }).get(sloRoute, async ({
13423
+ params: t31.Object({ organizationId: t31.String() }),
13424
+ query: t31.Object({
13425
+ RelayState: t31.Optional(t31.String()),
13426
+ SAMLRequest: t31.Optional(t31.String()),
13427
+ SAMLResponse: t31.Optional(t31.String()),
13428
+ SigAlg: t31.Optional(t31.String()),
13429
+ Signature: t31.Optional(t31.String())
13430
+ })
13431
+ }, async ({
13409
13432
  cookie: { user_session_id },
13410
13433
  params: { organizationId },
13411
13434
  query: {
@@ -13486,18 +13509,6 @@ var samlSsoRoutes = ({
13486
13509
  return redirect(url);
13487
13510
  }
13488
13511
  return redirect(toSafeLocalPath(info.relayState ?? RelayState));
13489
- }, {
13490
- cookie: t31.Cookie({
13491
- user_session_id: t31.Optional(userSessionIdTypebox)
13492
- }),
13493
- params: t31.Object({ organizationId: t31.String() }),
13494
- query: t31.Object({
13495
- RelayState: t31.Optional(t31.String()),
13496
- SAMLRequest: t31.Optional(t31.String()),
13497
- SAMLResponse: t31.Optional(t31.String()),
13498
- SigAlg: t31.Optional(t31.String()),
13499
- Signature: t31.Optional(t31.String())
13500
- })
13501
13512
  });
13502
13513
  };
13503
13514
 
@@ -13545,7 +13556,7 @@ var webauthnRoutes = ({
13545
13556
  secure,
13546
13557
  value: challenge
13547
13558
  });
13548
- return new Elysia40().use(sessionStore()).post(`${webauthnRoute}/register/options`, async ({
13559
+ return new Elysia40().use(sessionStore()).post(`${webauthnRoute}/register/options`, { cookie: challengeCookie }, async ({
13549
13560
  cookie: { user_session_id, webauthn_challenge },
13550
13561
  status,
13551
13562
  store: { session }
@@ -13574,7 +13585,10 @@ var webauthnRoutes = ({
13574
13585
  });
13575
13586
  setChallenge(webauthn_challenge, challenge);
13576
13587
  return status("OK", options);
13577
- }, { cookie: challengeCookie }).post(`${webauthnRoute}/register/verify`, async ({
13588
+ }).post(`${webauthnRoute}/register/verify`, {
13589
+ body: t32.Object({}, { additionalProperties: true }),
13590
+ cookie: challengeCookie
13591
+ }, async ({
13578
13592
  body,
13579
13593
  cookie: { user_session_id, webauthn_challenge },
13580
13594
  status,
@@ -13622,17 +13636,17 @@ var webauthnRoutes = ({
13622
13636
  credentialId: result.credential.credentialId,
13623
13637
  verified: true
13624
13638
  });
13625
- }, {
13626
- body: t32.Object({}, { additionalProperties: true }),
13627
- cookie: challengeCookie
13628
- }).post(`${webauthnRoute}/authenticate/options`, async ({ cookie: { webauthn_challenge }, status }) => {
13639
+ }).post(`${webauthnRoute}/authenticate/options`, { cookie: challengeCookie }, async ({ cookie: { webauthn_challenge }, status }) => {
13629
13640
  const { challenge, options } = await webauthnAdapter.createAuthenticationOptions({
13630
13641
  allowCredentials: [],
13631
13642
  rpId
13632
13643
  });
13633
13644
  setChallenge(webauthn_challenge, challenge);
13634
13645
  return status("OK", options);
13635
- }, { cookie: challengeCookie }).post(`${webauthnRoute}/authenticate/verify`, async ({
13646
+ }).post(`${webauthnRoute}/authenticate/verify`, {
13647
+ body: t32.Object({ id: t32.String() }, { additionalProperties: true }),
13648
+ cookie: challengeCookie
13649
+ }, async ({
13636
13650
  body,
13637
13651
  cookie: { user_session_id, webauthn_challenge },
13638
13652
  status,
@@ -13686,9 +13700,6 @@ var webauthnRoutes = ({
13686
13700
  });
13687
13701
  await onWebAuthnAuthenticated?.({ user, userSessionId });
13688
13702
  return status("OK", { status: "authenticated" });
13689
- }, {
13690
- body: t32.Object({ id: t32.String() }, { additionalProperties: true }),
13691
- cookie: challengeCookie
13692
13703
  });
13693
13704
  };
13694
13705
 
@@ -32568,7 +32579,7 @@ var createNeonLinkedProviderGrantStore = (db) => ({
32568
32579
  owner_ref: grant.ownerRef,
32569
32580
  provider_family: grant.providerFamily,
32570
32581
  provider_subject: grant.providerSubject,
32571
- refresh_token_ciphertext: grant.refreshTokenCiphertext ?? null,
32582
+ refresh_token_ciphertext: sql`coalesce(excluded.refresh_token_ciphertext, ${linkedProviderGrantsTable.refresh_token_ciphertext})`,
32572
32583
  status: grant.status,
32573
32584
  token_type: grant.tokenType ?? null,
32574
32585
  updated_at: new Date(grant.updatedAt)
@@ -32627,7 +32638,11 @@ var createInMemoryLinkedProviderStores = (input = {}) => {
32627
32638
  [...bindings.entries()].filter(([, binding]) => binding.grantId === id).forEach(([bindingId2]) => bindings.delete(bindingId2));
32628
32639
  },
32629
32640
  saveGrant: async (grant) => {
32630
- grants.set(grant.id, cloneGrant(grant));
32641
+ const existing = grants.get(grant.id);
32642
+ grants.set(grant.id, cloneGrant({
32643
+ ...grant,
32644
+ refreshTokenCiphertext: grant.refreshTokenCiphertext ?? existing?.refreshTokenCiphertext
32645
+ }));
32631
32646
  }
32632
32647
  };
32633
32648
  const bindingStore = {
@@ -32653,14 +32668,17 @@ var requireAuthPlugin = ({
32653
32668
  } = {}) => new Elysia41({
32654
32669
  name: "@absolutejs/auth/require-auth",
32655
32670
  seed: pluginDependencySeed(authSessionStore)
32656
- }).use(sessionStore()).guard({ cookie: t33.Cookie({ user_session_id: userSessionIdTypebox }) }).resolve(async ({ store: { session }, cookie: { user_session_id } }) => {
32671
+ }).use(sessionStore()).guard({
32672
+ cookie: t33.Cookie({ user_session_id: userSessionIdTypebox }),
32673
+ schema: "merge"
32674
+ }).derive(async ({ store: { session }, cookie: { user_session_id } }) => {
32657
32675
  const { user } = await getStatusFromSource({
32658
32676
  authSessionStore,
32659
32677
  session,
32660
32678
  user_session_id
32661
32679
  });
32662
32680
  return { user: user ?? null };
32663
- }).onBeforeHandle(({ user, status }) => user === null ? status("Unauthorized", "User is not authenticated") : undefined).as("global");
32681
+ }).beforeHandle(({ user, status }) => user === null ? status("Unauthorized", "User is not authenticated") : undefined).as("global");
32664
32682
  // src/session/impersonation.ts
32665
32683
  init_constants();
32666
32684
  var DEFAULT_IMPERSONATION_TTL_MS = MILLISECONDS_IN_AN_HOUR;
@@ -34112,7 +34130,15 @@ var vciRoutes = ({
34112
34130
  config: vciConfig,
34113
34131
  issuer: issuerUrl,
34114
34132
  vciRoute
34115
- }))).post(credentialRoute, async ({ body, headers }) => {
34133
+ }))).post(credentialRoute, {
34134
+ body: t34.Object({
34135
+ format: t34.Optional(t34.Union([t34.Literal("vc+sd-jwt")])),
34136
+ proof: t34.Optional(t34.Object({
34137
+ jwt: t34.String(),
34138
+ proof_type: t34.Literal("jwt")
34139
+ }))
34140
+ })
34141
+ }, async ({ body, headers }) => {
34116
34142
  const accessToken = extractBearer(headers.authorization);
34117
34143
  if (accessToken === undefined) {
34118
34144
  return errorBody("invalid_token", HTTP_UNAUTHORIZED5);
@@ -34130,14 +34156,6 @@ var vciRoutes = ({
34130
34156
  if (!result.ok)
34131
34157
  return errorBody(result.error, HTTP_BAD_REQUEST4);
34132
34158
  return Response.json({ credential: result.credential, format: result.format }, { status: HTTP_OK4 });
34133
- }, {
34134
- body: t34.Object({
34135
- format: t34.Optional(t34.Union([t34.Literal("vc+sd-jwt")])),
34136
- proof: t34.Optional(t34.Object({
34137
- jwt: t34.String(),
34138
- proof_type: t34.Literal("jwt")
34139
- }))
34140
- })
34141
34159
  }).post(nonceRoute, async () => {
34142
34160
  if (vciConfig.credentialNonceStore === undefined) {
34143
34161
  return errorBody("not_supported", HTTP_BAD_REQUEST4);
@@ -34269,7 +34287,7 @@ var statusListRoutes = ({
34269
34287
  ttlSeconds
34270
34288
  }) => {
34271
34289
  const listRoute = `${statusRoute}/:listId`;
34272
- return new Elysia43().get(listRoute, async ({ params: { listId } }) => {
34290
+ return new Elysia43().get(listRoute, { params: t35.Object({ listId: t35.String() }) }, async ({ params: { listId } }) => {
34273
34291
  const bits = await getStatusList(listId);
34274
34292
  if (bits === undefined) {
34275
34293
  return new Response("Not found", { status: HTTP_NOT_FOUND });
@@ -34285,7 +34303,7 @@ var statusListRoutes = ({
34285
34303
  headers: { "content-type": STATUS_LIST_SUB_TYP },
34286
34304
  status: HTTP_OK5
34287
34305
  });
34288
- }, { params: t35.Object({ listId: t35.String() }) });
34306
+ });
34289
34307
  };
34290
34308
  // src/vc/openid4vp.ts
34291
34309
  init_crypto();
@@ -34509,7 +34527,13 @@ var vpRoutes = ({
34509
34527
  const authorizeRoute = `${vpRoute}/authorize`;
34510
34528
  const requestRoute = `${vpRoute}/request/:id`;
34511
34529
  const responseRoute = `${vpRoute}/response`;
34512
- return new Elysia44().post(authorizeRoute, async ({ body }) => {
34530
+ return new Elysia44().post(authorizeRoute, {
34531
+ body: t36.Object({
34532
+ client_id: t36.Optional(t36.String()),
34533
+ requested_claims: t36.Array(t36.String()),
34534
+ state: t36.Optional(t36.String())
34535
+ })
34536
+ }, async ({ body }) => {
34513
34537
  const input = {
34514
34538
  clientId: body.client_id ?? defaultClientId,
34515
34539
  requestedClaims: body.requested_claims,
@@ -34526,13 +34550,7 @@ var vpRoutes = ({
34526
34550
  request_uri: result.requestUri,
34527
34551
  requestId: result.request.requestId
34528
34552
  }, { status: HTTP_OK6 });
34529
- }, {
34530
- body: t36.Object({
34531
- client_id: t36.Optional(t36.String()),
34532
- requested_claims: t36.Array(t36.String()),
34533
- state: t36.Optional(t36.String())
34534
- })
34535
- }).get(requestRoute, async ({ params: { id } }) => {
34553
+ }).get(requestRoute, { params: t36.Object({ id: t36.String() }) }, async ({ params: { id } }) => {
34536
34554
  const stored = await vpConfig.requestStore.getRequest(id);
34537
34555
  if (stored === undefined) {
34538
34556
  return errorBody2("unknown_request", HTTP_NOT_FOUND2);
@@ -34556,7 +34574,13 @@ var vpRoutes = ({
34556
34574
  },
34557
34575
  status: HTTP_OK6
34558
34576
  });
34559
- }, { params: t36.Object({ id: t36.String() }) }).post(responseRoute, async ({ body }) => {
34577
+ }).post(responseRoute, {
34578
+ body: t36.Object({
34579
+ presentation_submission: t36.Optional(t36.Unknown()),
34580
+ state: t36.Optional(t36.String()),
34581
+ vp_token: t36.String()
34582
+ })
34583
+ }, async ({ body }) => {
34560
34584
  const requestId = body.state;
34561
34585
  if (requestId === undefined) {
34562
34586
  return errorBody2("missing_state", HTTP_BAD_REQUEST5);
@@ -34576,12 +34600,6 @@ var vpRoutes = ({
34576
34600
  protected_claims: result.verified.protectedClaims,
34577
34601
  verified: true
34578
34602
  }, { status: HTTP_OK6 });
34579
- }, {
34580
- body: t36.Object({
34581
- presentation_submission: t36.Optional(t36.Unknown()),
34582
- state: t36.Optional(t36.String()),
34583
- vp_token: t36.String()
34584
- })
34585
34603
  });
34586
34604
  };
34587
34605
  var passthroughStore = (request) => ({
@@ -38056,13 +38074,7 @@ var samlIdpRoutes = ({
38056
38074
  user: userSession.user
38057
38075
  });
38058
38076
  };
38059
- return new Elysia45().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
38060
- binding: "POST",
38061
- body,
38062
- inMemorySession: store.session,
38063
- request,
38064
- userSessionIdValue: user_session_id.value
38065
- }), {
38077
+ return new Elysia45().use(sessionStore()).post(ssoIdpRoute, {
38066
38078
  body: t37.Object({
38067
38079
  RelayState: t37.Optional(t37.String()),
38068
38080
  SAMLRequest: t37.Optional(t37.String())
@@ -38070,13 +38082,13 @@ var samlIdpRoutes = ({
38070
38082
  cookie: t37.Cookie({
38071
38083
  user_session_id: t37.Optional(userSessionIdTypebox)
38072
38084
  })
38073
- }).get(ssoIdpRoute, async ({ cookie: { user_session_id }, query, request, store }) => handleSpInitiated({
38074
- binding: "Redirect",
38075
- body: query,
38085
+ }, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
38086
+ binding: "POST",
38087
+ body,
38076
38088
  inMemorySession: store.session,
38077
38089
  request,
38078
38090
  userSessionIdValue: user_session_id.value
38079
- }), {
38091
+ })).get(ssoIdpRoute, {
38080
38092
  cookie: t37.Cookie({
38081
38093
  user_session_id: t37.Optional(userSessionIdTypebox)
38082
38094
  }),
@@ -38086,7 +38098,21 @@ var samlIdpRoutes = ({
38086
38098
  SigAlg: t37.Optional(t37.String()),
38087
38099
  Signature: t37.Optional(t37.String())
38088
38100
  })
38089
- }).get(idpInitiateRoute, async ({
38101
+ }, async ({ cookie: { user_session_id }, query, request, store }) => handleSpInitiated({
38102
+ binding: "Redirect",
38103
+ body: query,
38104
+ inMemorySession: store.session,
38105
+ request,
38106
+ userSessionIdValue: user_session_id.value
38107
+ })).get(idpInitiateRoute, {
38108
+ cookie: t37.Cookie({
38109
+ user_session_id: t37.Optional(userSessionIdTypebox)
38110
+ }),
38111
+ query: t37.Object({
38112
+ RelayState: t37.Optional(t37.String()),
38113
+ sp: t37.Optional(t37.String())
38114
+ })
38115
+ }, async ({
38090
38116
  cookie: { user_session_id },
38091
38117
  query: { sp: serviceProviderEntityId, RelayState: relayState },
38092
38118
  request,
@@ -38119,14 +38145,6 @@ var samlIdpRoutes = ({
38119
38145
  serviceProviderEntityId: serviceProvider.entityId,
38120
38146
  user: userSession.user
38121
38147
  });
38122
- }, {
38123
- cookie: t37.Cookie({
38124
- user_session_id: t37.Optional(userSessionIdTypebox)
38125
- }),
38126
- query: t37.Object({
38127
- RelayState: t37.Optional(t37.String()),
38128
- sp: t37.Optional(t37.String())
38129
- })
38130
38148
  }).get(idpMetadataRoute, async ({ request }) => xmlResponse(await idpAdapter.getIdpMetadata({
38131
38149
  entityId: idpEntityId,
38132
38150
  ssoUrl: ssoUrlFor(request.url)
@@ -38631,10 +38649,7 @@ var buildAuthApplications = async (configuration) => {
38631
38649
  profileRoute
38632
38650
  })
38633
38651
  ]);
38634
- const featureRoutes = new Elysia46({
38635
- name: "@absolutejs/auth/feature-routes",
38636
- seed: pluginSeed
38637
- }).use([
38652
+ const identityFeatureRoutes = new Elysia46().use([
38638
38653
  auditedCredentials ? credentialRoutes({
38639
38654
  ...auditedCredentials,
38640
38655
  authSessionStore,
@@ -38664,7 +38679,9 @@ var buildAuthApplications = async (configuration) => {
38664
38679
  authSessionStore,
38665
38680
  cookieSecure: resolvedCookieSecure,
38666
38681
  samlAdapter: sso.samlAdapter
38667
- }) : new Elysia46,
38682
+ }) : new Elysia46
38683
+ ]);
38684
+ const organizationFeatureRoutes = new Elysia46().use([
38668
38685
  sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
38669
38686
  getOrganizationByEmailDomain: sso.getOrganizationByEmailDomain,
38670
38687
  ssoConnectionStore: sso.ssoConnectionStore,
@@ -38685,7 +38702,9 @@ var buildAuthApplications = async (configuration) => {
38685
38702
  ...roles,
38686
38703
  authSessionStore,
38687
38704
  emit: auditEmit
38688
- }) : new Elysia46,
38705
+ }) : new Elysia46
38706
+ ]);
38707
+ const extendedFeatureRoutes = new Elysia46().use([
38689
38708
  portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia46,
38690
38709
  webauthn ? webauthnRoutes({
38691
38710
  ...webauthn,
@@ -38701,6 +38720,14 @@ var buildAuthApplications = async (configuration) => {
38701
38720
  createConfiguredAuthHtmxRoutes({ authSessionStore, config: htmx }),
38702
38721
  agentAuthRoutes(resolvedAgentAuth)
38703
38722
  ]);
38723
+ const featureRoutes = new Elysia46({
38724
+ name: "@absolutejs/auth/feature-routes",
38725
+ seed: pluginSeed
38726
+ }).use([
38727
+ identityFeatureRoutes,
38728
+ organizationFeatureRoutes,
38729
+ extendedFeatureRoutes
38730
+ ]);
38704
38731
  const authContext = createAuthContext({
38705
38732
  agentAuth: resolvedAgentAuth,
38706
38733
  authorization,
@@ -38898,5 +38925,5 @@ export {
38898
38925
  VerificationProviderError
38899
38926
  };
38900
38927
 
38901
- //# debugId=5901150ECA00DB6964756E2164756E21
38928
+ //# debugId=E426F833E493795E64756E2164756E21
38902
38929
  //# sourceMappingURL=server.js.map