@absolutejs/auth 0.62.0 → 0.63.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.
@@ -0,0 +1,43 @@
1
+ import { Elysia } from 'elysia';
2
+ import type { AuthSessionSource } from '../session/types';
3
+ export declare const requireAuthPlugin: <UserType>({ authSessionStore }?: {
4
+ authSessionStore?: AuthSessionSource<UserType>;
5
+ }) => Elysia<"", {
6
+ decorator: {};
7
+ store: {
8
+ session: import("..").SessionRecord<UserType>;
9
+ unregisteredSession: import("..").UnregisteredSessionRecord;
10
+ };
11
+ derive: {};
12
+ resolve: {
13
+ readonly user: NonNullable<UserType> | null;
14
+ };
15
+ }, {
16
+ typebox: {};
17
+ error: {};
18
+ }, {
19
+ schema: import("elysia").UnwrapRoute<{
20
+ cookie: import("@sinclair/typebox").TObject<{
21
+ user_session_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TTemplateLiteralSyntax<"${string}-${string}-${string}-${string}-${string}">>;
22
+ }>;
23
+ }, {}, "">;
24
+ standaloneSchema: {};
25
+ macro: {};
26
+ macroFn: {};
27
+ parser: {};
28
+ response: {
29
+ 401: "User is not authenticated";
30
+ };
31
+ }, {}, {
32
+ derive: {};
33
+ resolve: {};
34
+ schema: {};
35
+ standaloneSchema: {};
36
+ response: {};
37
+ }, {
38
+ derive: {};
39
+ resolve: {};
40
+ schema: {};
41
+ standaloneSchema: {};
42
+ response: {};
43
+ }>;
package/dist/server.d.ts CHANGED
@@ -14,6 +14,7 @@ export type { SetupCapability, SetupSession, SetupSessionStore } from './portal/
14
14
  export { createSetupSession } from './portal/operations';
15
15
  export { createPostgresSetupSessionStore } from './portal/postgresSetupSessionStore';
16
16
  export { protectRoutePlugin } from './routes/protectRoute';
17
+ export { requireAuthPlugin } from './routes/requireAuth';
17
18
  export type { ScimConfig } from './scim/config';
18
19
  export type { ScimFilter, ScimGroup, ScimGroupInput, ScimTokenStore, ScimUser, ScimUserInput } from './scim/types';
19
20
  export { createPostgresScimTokenStore } from './scim/postgresScimTokenStore';
package/dist/server.js CHANGED
@@ -3978,7 +3978,7 @@ var createCustomOAuth2Client = (providerConfig, credentials) => buildOAuth2Clien
3978
3978
  var createOAuth2Client = (providerName, config) => buildOAuth2Client(providers[providerName], config);
3979
3979
 
3980
3980
  // src/index.ts
3981
- import { Elysia as Elysia45 } from "elysia";
3981
+ import { Elysia as Elysia46 } from "elysia";
3982
3982
 
3983
3983
  // src/apikeys/routes.ts
3984
3984
  import { Elysia, t } from "elysia";
@@ -32528,6 +32528,21 @@ var createInMemoryLinkedProviderStores = (input = {}) => {
32528
32528
  };
32529
32529
  return { bindingStore, grantStore };
32530
32530
  };
32531
+ // src/routes/requireAuth.ts
32532
+ import { Elysia as Elysia41, t as t33 } from "elysia";
32533
+ var requireAuthPlugin = ({
32534
+ authSessionStore
32535
+ } = {}) => new Elysia41({
32536
+ name: "@absolutejs/auth/require-auth",
32537
+ seed: pluginDependencySeed(authSessionStore)
32538
+ }).use(sessionStore()).guard({ cookie: t33.Cookie({ user_session_id: userSessionIdTypebox }) }).resolve(async ({ store: { session }, cookie: { user_session_id } }) => {
32539
+ const { user } = await getStatusFromSource({
32540
+ authSessionStore,
32541
+ session,
32542
+ user_session_id
32543
+ });
32544
+ return { user: user ?? null };
32545
+ }).onBeforeHandle(({ user, status }) => user === null ? status("Unauthorized", "User is not authenticated") : undefined).as("global");
32531
32546
  // src/session/impersonation.ts
32532
32547
  init_constants();
32533
32548
  var DEFAULT_IMPERSONATION_TTL_MS = MILLISECONDS_IN_AN_HOUR;
@@ -33946,7 +33961,7 @@ var createInMemoryCredentialOfferStore = () => {
33946
33961
  };
33947
33962
  };
33948
33963
  // src/oidc/vciRoutes.ts
33949
- import { Elysia as Elysia41, t as t33 } from "elysia";
33964
+ import { Elysia as Elysia42, t as t34 } from "elysia";
33950
33965
  var HTTP_OK4 = 200;
33951
33966
  var HTTP_BAD_REQUEST4 = 400;
33952
33967
  var HTTP_UNAUTHORIZED5 = 401;
@@ -33971,7 +33986,7 @@ var vciRoutes = ({
33971
33986
  const credentialRoute = `${vciRoute}/credential`;
33972
33987
  const nonceRoute = `${vciRoute}/nonce`;
33973
33988
  const vciSigningKey = vciConfig.signingKey ?? signingKey;
33974
- return new Elysia41().get("/.well-known/openid-credential-issuer", () => Response.json(buildIssuerMetadata({
33989
+ return new Elysia42().get("/.well-known/openid-credential-issuer", () => Response.json(buildIssuerMetadata({
33975
33990
  config: vciConfig,
33976
33991
  issuer: issuerUrl,
33977
33992
  vciRoute
@@ -33994,11 +34009,11 @@ var vciRoutes = ({
33994
34009
  return errorBody(result.error, HTTP_BAD_REQUEST4);
33995
34010
  return Response.json({ credential: result.credential, format: result.format }, { status: HTTP_OK4 });
33996
34011
  }, {
33997
- body: t33.Object({
33998
- format: t33.Optional(t33.Union([t33.Literal("vc+sd-jwt")])),
33999
- proof: t33.Optional(t33.Object({
34000
- jwt: t33.String(),
34001
- proof_type: t33.Literal("jwt")
34012
+ body: t34.Object({
34013
+ format: t34.Optional(t34.Union([t34.Literal("vc+sd-jwt")])),
34014
+ proof: t34.Optional(t34.Object({
34015
+ jwt: t34.String(),
34016
+ proof_type: t34.Literal("jwt")
34002
34017
  }))
34003
34018
  })
34004
34019
  }).post(nonceRoute, async () => {
@@ -34120,7 +34135,7 @@ var verifyStatusListJwt = async ({
34120
34135
  };
34121
34136
  };
34122
34137
  // src/vc/statusListRoutes.ts
34123
- import { Elysia as Elysia42, t as t34 } from "elysia";
34138
+ import { Elysia as Elysia43, t as t35 } from "elysia";
34124
34139
  var HTTP_OK5 = 200;
34125
34140
  var HTTP_NOT_FOUND = 404;
34126
34141
  var DEFAULT_STATUS_ROUTE = "/vc/status";
@@ -34132,7 +34147,7 @@ var statusListRoutes = ({
34132
34147
  ttlSeconds
34133
34148
  }) => {
34134
34149
  const listRoute = `${statusRoute}/:listId`;
34135
- return new Elysia42().get(listRoute, async ({ params: { listId } }) => {
34150
+ return new Elysia43().get(listRoute, async ({ params: { listId } }) => {
34136
34151
  const bits = await getStatusList(listId);
34137
34152
  if (bits === undefined) {
34138
34153
  return new Response("Not found", { status: HTTP_NOT_FOUND });
@@ -34148,7 +34163,7 @@ var statusListRoutes = ({
34148
34163
  headers: { "content-type": STATUS_LIST_SUB_TYP },
34149
34164
  status: HTTP_OK5
34150
34165
  });
34151
- }, { params: t34.Object({ listId: t34.String() }) });
34166
+ }, { params: t35.Object({ listId: t35.String() }) });
34152
34167
  };
34153
34168
  // src/vc/openid4vp.ts
34154
34169
  init_crypto();
@@ -34353,7 +34368,7 @@ var createInMemoryPresentationRequestStore = () => {
34353
34368
  };
34354
34369
  };
34355
34370
  // src/vc/vpRoutes.ts
34356
- import { Elysia as Elysia43, t as t35 } from "elysia";
34371
+ import { Elysia as Elysia44, t as t36 } from "elysia";
34357
34372
  var HTTP_OK6 = 200;
34358
34373
  var HTTP_BAD_REQUEST5 = 400;
34359
34374
  var HTTP_NOT_FOUND2 = 404;
@@ -34372,7 +34387,7 @@ var vpRoutes = ({
34372
34387
  const authorizeRoute = `${vpRoute}/authorize`;
34373
34388
  const requestRoute = `${vpRoute}/request/:id`;
34374
34389
  const responseRoute = `${vpRoute}/response`;
34375
- return new Elysia43().post(authorizeRoute, async ({ body }) => {
34390
+ return new Elysia44().post(authorizeRoute, async ({ body }) => {
34376
34391
  const input = {
34377
34392
  clientId: body.client_id ?? defaultClientId,
34378
34393
  requestedClaims: body.requested_claims,
@@ -34390,10 +34405,10 @@ var vpRoutes = ({
34390
34405
  requestId: result.request.requestId
34391
34406
  }, { status: HTTP_OK6 });
34392
34407
  }, {
34393
- body: t35.Object({
34394
- client_id: t35.Optional(t35.String()),
34395
- requested_claims: t35.Array(t35.String()),
34396
- state: t35.Optional(t35.String())
34408
+ body: t36.Object({
34409
+ client_id: t36.Optional(t36.String()),
34410
+ requested_claims: t36.Array(t36.String()),
34411
+ state: t36.Optional(t36.String())
34397
34412
  })
34398
34413
  }).get(requestRoute, async ({ params: { id } }) => {
34399
34414
  const stored = await vpConfig.requestStore.getRequest(id);
@@ -34419,7 +34434,7 @@ var vpRoutes = ({
34419
34434
  },
34420
34435
  status: HTTP_OK6
34421
34436
  });
34422
- }, { params: t35.Object({ id: t35.String() }) }).post(responseRoute, async ({ body }) => {
34437
+ }, { params: t36.Object({ id: t36.String() }) }).post(responseRoute, async ({ body }) => {
34423
34438
  const requestId = body.state;
34424
34439
  if (requestId === undefined) {
34425
34440
  return errorBody2("missing_state", HTTP_BAD_REQUEST5);
@@ -34440,10 +34455,10 @@ var vpRoutes = ({
34440
34455
  verified: true
34441
34456
  }, { status: HTTP_OK6 });
34442
34457
  }, {
34443
- body: t35.Object({
34444
- presentation_submission: t35.Optional(t35.Unknown()),
34445
- state: t35.Optional(t35.String()),
34446
- vp_token: t35.String()
34458
+ body: t36.Object({
34459
+ presentation_submission: t36.Optional(t36.Unknown()),
34460
+ state: t36.Optional(t36.String()),
34461
+ vp_token: t36.String()
34447
34462
  })
34448
34463
  });
34449
34464
  };
@@ -37799,7 +37814,7 @@ var blockMigrations = {
37799
37814
  webhooks: initMigration("webhooks", [webhookDeliveriesTable])
37800
37815
  };
37801
37816
  // src/sso/samlIdpRoutes.ts
37802
- import { Elysia as Elysia44, t as t36 } from "elysia";
37817
+ import { Elysia as Elysia45, t as t37 } from "elysia";
37803
37818
  var HTTP_BAD_REQUEST6 = 400;
37804
37819
  var HTTP_UNAUTHORIZED6 = 401;
37805
37820
  var HTTP_FOUND2 = 302;
@@ -37909,19 +37924,19 @@ var samlIdpRoutes = ({
37909
37924
  user: userSession.user
37910
37925
  });
37911
37926
  };
37912
- return new Elysia44().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
37927
+ return new Elysia45().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
37913
37928
  binding: "POST",
37914
37929
  body,
37915
37930
  inMemorySession: store.session,
37916
37931
  request,
37917
37932
  userSessionIdValue: user_session_id.value
37918
37933
  }), {
37919
- body: t36.Object({
37920
- RelayState: t36.Optional(t36.String()),
37921
- SAMLRequest: t36.Optional(t36.String())
37934
+ body: t37.Object({
37935
+ RelayState: t37.Optional(t37.String()),
37936
+ SAMLRequest: t37.Optional(t37.String())
37922
37937
  }),
37923
- cookie: t36.Cookie({
37924
- user_session_id: t36.Optional(userSessionIdTypebox)
37938
+ cookie: t37.Cookie({
37939
+ user_session_id: t37.Optional(userSessionIdTypebox)
37925
37940
  })
37926
37941
  }).get(ssoIdpRoute, async ({ cookie: { user_session_id }, query, request, store }) => handleSpInitiated({
37927
37942
  binding: "Redirect",
@@ -37930,14 +37945,14 @@ var samlIdpRoutes = ({
37930
37945
  request,
37931
37946
  userSessionIdValue: user_session_id.value
37932
37947
  }), {
37933
- cookie: t36.Cookie({
37934
- user_session_id: t36.Optional(userSessionIdTypebox)
37948
+ cookie: t37.Cookie({
37949
+ user_session_id: t37.Optional(userSessionIdTypebox)
37935
37950
  }),
37936
- query: t36.Object({
37937
- RelayState: t36.Optional(t36.String()),
37938
- SAMLRequest: t36.Optional(t36.String()),
37939
- SigAlg: t36.Optional(t36.String()),
37940
- Signature: t36.Optional(t36.String())
37951
+ query: t37.Object({
37952
+ RelayState: t37.Optional(t37.String()),
37953
+ SAMLRequest: t37.Optional(t37.String()),
37954
+ SigAlg: t37.Optional(t37.String()),
37955
+ Signature: t37.Optional(t37.String())
37941
37956
  })
37942
37957
  }).get(idpInitiateRoute, async ({
37943
37958
  cookie: { user_session_id },
@@ -37973,12 +37988,12 @@ var samlIdpRoutes = ({
37973
37988
  user: userSession.user
37974
37989
  });
37975
37990
  }, {
37976
- cookie: t36.Cookie({
37977
- user_session_id: t36.Optional(userSessionIdTypebox)
37991
+ cookie: t37.Cookie({
37992
+ user_session_id: t37.Optional(userSessionIdTypebox)
37978
37993
  }),
37979
- query: t36.Object({
37980
- RelayState: t36.Optional(t36.String()),
37981
- sp: t36.Optional(t36.String())
37994
+ query: t37.Object({
37995
+ RelayState: t37.Optional(t37.String()),
37996
+ sp: t37.Optional(t37.String())
37982
37997
  })
37983
37998
  }).get(idpMetadataRoute, async ({ request }) => xmlResponse(await idpAdapter.getIdpMetadata({
37984
37999
  entityId: idpEntityId,
@@ -38427,7 +38442,7 @@ var buildAuthApplications = async (configuration) => {
38427
38442
  const auditedOnRevocationSuccess = auditEmit ? composeRevocationAudit(onRevocationSuccess, auditEmit) : onRevocationSuccess;
38428
38443
  const auditedOnSignOut = auditEmit ? composeSignOutAudit(onSignOut, auditEmit) : onSignOut;
38429
38444
  const pluginSeed = pluginDependencySeed(configuration);
38430
- const coreRoutes = new Elysia45({
38445
+ const coreRoutes = new Elysia46({
38431
38446
  name: "@absolutejs/auth/core-routes",
38432
38447
  seed: pluginSeed
38433
38448
  }).use([
@@ -38484,7 +38499,7 @@ var buildAuthApplications = async (configuration) => {
38484
38499
  profileRoute
38485
38500
  })
38486
38501
  ]);
38487
- const featureRoutes = new Elysia45({
38502
+ const featureRoutes = new Elysia46({
38488
38503
  name: "@absolutejs/auth/feature-routes",
38489
38504
  seed: pluginSeed
38490
38505
  }).use([
@@ -38493,64 +38508,64 @@ var buildAuthApplications = async (configuration) => {
38493
38508
  authSessionStore,
38494
38509
  cookieSecure: resolvedCookieSecure,
38495
38510
  lockoutGuard
38496
- }) : new Elysia45,
38511
+ }) : new Elysia46,
38497
38512
  auditedMfa ? mfaRoutes({
38498
38513
  ...auditedMfa,
38499
38514
  authSessionStore,
38500
38515
  cookieSecure: resolvedCookieSecure,
38501
38516
  verificationProvider
38502
- }) : new Elysia45,
38517
+ }) : new Elysia46,
38503
38518
  passwordless ? passwordlessRoutes({
38504
38519
  ...passwordless,
38505
38520
  authSessionStore,
38506
38521
  cookieSecure: resolvedCookieSecure,
38507
38522
  emit: auditEmit
38508
- }) : new Elysia45,
38509
- sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia45,
38523
+ }) : new Elysia46,
38524
+ sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia46,
38510
38525
  sso ? oidcSsoRoutes({
38511
38526
  ...sso,
38512
38527
  authSessionStore,
38513
38528
  cookieSecure: resolvedCookieSecure
38514
- }) : new Elysia45,
38529
+ }) : new Elysia46,
38515
38530
  sso && sso.samlAdapter ? samlSsoRoutes({
38516
38531
  ...sso,
38517
38532
  authSessionStore,
38518
38533
  cookieSecure: resolvedCookieSecure,
38519
38534
  samlAdapter: sso.samlAdapter
38520
- }) : new Elysia45,
38535
+ }) : new Elysia46,
38521
38536
  sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
38522
38537
  getOrganizationByEmailDomain: sso.getOrganizationByEmailDomain,
38523
38538
  ssoConnectionStore: sso.ssoConnectionStore,
38524
38539
  ssoRoute: sso.ssoRoute
38525
- }) : new Elysia45,
38526
- scim ? scimRoutes(scim) : new Elysia45,
38527
- apikeys ? apiKeysRoutes(apikeys) : new Elysia45,
38540
+ }) : new Elysia46,
38541
+ scim ? scimRoutes(scim) : new Elysia46,
38542
+ apikeys ? apiKeysRoutes(apikeys) : new Elysia46,
38528
38543
  oidcConfig ? oidcProviderRoutes({
38529
38544
  ...oidcConfig,
38530
38545
  authSessionStore
38531
- }) : new Elysia45,
38546
+ }) : new Elysia46,
38532
38547
  organizations ? organizationRoutes({
38533
38548
  ...organizations,
38534
38549
  authSessionStore,
38535
38550
  emit: auditEmit
38536
- }) : new Elysia45,
38551
+ }) : new Elysia46,
38537
38552
  roles ? roleRoutes({
38538
38553
  ...roles,
38539
38554
  authSessionStore,
38540
38555
  emit: auditEmit
38541
- }) : new Elysia45,
38542
- portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia45,
38556
+ }) : new Elysia46,
38557
+ portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia46,
38543
38558
  webauthn ? webauthnRoutes({
38544
38559
  ...webauthn,
38545
38560
  authSessionStore,
38546
38561
  cookieSecure: resolvedCookieSecure,
38547
38562
  emit: auditEmit
38548
- }) : new Elysia45,
38563
+ }) : new Elysia46,
38549
38564
  compliance ? complianceRoutes({
38550
38565
  ...compliance,
38551
38566
  authSessionStore,
38552
38567
  emit: auditEmit
38553
- }) : new Elysia45,
38568
+ }) : new Elysia46,
38554
38569
  createConfiguredAuthHtmxRoutes({ authSessionStore, config: htmx }),
38555
38570
  agentAuthRoutes(resolvedAgentAuth)
38556
38571
  ]);
@@ -38565,7 +38580,7 @@ var buildAuthApplications = async (configuration) => {
38565
38580
  };
38566
38581
  var auth = async (configuration) => {
38567
38582
  const { authContext, coreRoutes, featureRoutes } = await buildAuthApplications(configuration);
38568
- const application = new Elysia45({
38583
+ const application = new Elysia46({
38569
38584
  name: "@absolutejs/auth",
38570
38585
  seed: pluginDependencySeed(configuration)
38571
38586
  });
@@ -38733,6 +38748,7 @@ var createNodeSamlAdapter = async (options = {}) => {
38733
38748
  var auth2 = auth;
38734
38749
  export {
38735
38750
  userSessionIdTypebox,
38751
+ requireAuthPlugin,
38736
38752
  providers,
38737
38753
  protectRoutePlugin,
38738
38754
  isValidProviderOption,
@@ -38749,5 +38765,5 @@ export {
38749
38765
  VerificationProviderError
38750
38766
  };
38751
38767
 
38752
- //# debugId=E5516A34918E793A64756E2164756E21
38768
+ //# debugId=015C798311C7C14564756E2164756E21
38753
38769
  //# sourceMappingURL=server.js.map