@absolutejs/auth 0.70.0 → 0.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4775,6 +4775,118 @@ var stepUpPlugin = ({
4775
4775
  })
4776
4776
  })).as("global");
4777
4777
 
4778
+ // src/oidc/socketTickets.ts
4779
+ init_crypto();
4780
+ var DEFAULT_SOCKET_TICKET_TTL_MS = 30000;
4781
+ var TICKET_BYTES = 32;
4782
+ var consumeSocketTicket = async ({
4783
+ audience,
4784
+ getUser,
4785
+ now = Date.now(),
4786
+ store,
4787
+ ticket
4788
+ }) => {
4789
+ const record = await store.consumeTicket(await hashToken(ticket), now);
4790
+ if (!record || record.audience !== audience)
4791
+ return;
4792
+ const user = await getUser(record.subject);
4793
+ if (user === null)
4794
+ return;
4795
+ return {
4796
+ audience: record.audience,
4797
+ clientId: record.clientId,
4798
+ kind: "access-token",
4799
+ scopes: [...record.scopes],
4800
+ subject: record.subject,
4801
+ user
4802
+ };
4803
+ };
4804
+ var issueSocketTicket = async ({
4805
+ audience,
4806
+ clientId,
4807
+ now = Date.now(),
4808
+ scopes,
4809
+ store,
4810
+ subject,
4811
+ ttlMs = DEFAULT_SOCKET_TICKET_TTL_MS
4812
+ }) => {
4813
+ if (!Number.isFinite(ttlMs) || ttlMs <= 0)
4814
+ throw new Error("socketTicketTtlMs must be positive");
4815
+ const ticket = `ast_${generateSecureToken(TICKET_BYTES)}`;
4816
+ await store.saveTicket({
4817
+ audience,
4818
+ clientId,
4819
+ expiresAt: now + ttlMs,
4820
+ scopes: [...scopes],
4821
+ subject,
4822
+ ticketHash: await hashToken(ticket)
4823
+ });
4824
+ return { expiresInMs: ttlMs, ticket };
4825
+ };
4826
+
4827
+ // src/syncNamespace.ts
4828
+ var base64Url2 = (value) => {
4829
+ let binary = "";
4830
+ for (const byte of value)
4831
+ binary += String.fromCharCode(byte);
4832
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
4833
+ };
4834
+ var deriveAuthSyncNamespace = async ({
4835
+ clientId,
4836
+ issuer,
4837
+ partition,
4838
+ subject
4839
+ }) => {
4840
+ if (clientId.length === 0 || issuer.length === 0 || subject.length === 0)
4841
+ throw new TypeError("Auth Sync namespace requires issuer, clientId, and subject.");
4842
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([issuer, clientId, subject, partition ?? null])));
4843
+ return `auth:v1:${base64Url2(new Uint8Array(digest))}`;
4844
+ };
4845
+ var readAuthSyncPartition = (user) => {
4846
+ if (typeof user !== "object" || user === null)
4847
+ return;
4848
+ const value = Reflect.get(user, "absolutejs_sync_partition");
4849
+ return typeof value === "string" && value.length > 0 ? value : undefined;
4850
+ };
4851
+
4852
+ // src/syncBridge.ts
4853
+ var PWA_SYNC_CLIENT_ID = "@absolutejs/pwa";
4854
+ var toSyncContext = (authPrincipal) => authPrincipal ? { authPrincipal, user: authPrincipal.user } : undefined;
4855
+ var isSessionAuthPrincipal = (value) => typeof value === "object" && value !== null && Reflect.get(value, "kind") === "session" && typeof Reflect.get(value, "subject") === "string" && Reflect.get(value, "subject").length > 0 && Reflect.has(value, "user");
4856
+ var createAbsoluteAuthSyncBridge = (accessTokens) => ({
4857
+ consumeSocketTicket: async ({ audience, ticket }) => {
4858
+ const store = accessTokens.oidc.socketTicketStore;
4859
+ if (!store)
4860
+ return;
4861
+ return toSyncContext(await consumeSocketTicket({
4862
+ audience: audience ?? accessTokens.oidc.issuer,
4863
+ getUser: accessTokens.getUser,
4864
+ store,
4865
+ ticket
4866
+ }));
4867
+ },
4868
+ resolveBearer: async ({ authorization }) => toSyncContext(await resolveAccessTokenPrincipal({
4869
+ authorization,
4870
+ config: accessTokens
4871
+ })),
4872
+ resolveSession: async ({ authPrincipal }) => {
4873
+ if (!isSessionAuthPrincipal(authPrincipal))
4874
+ return;
4875
+ const context = toSyncContext(authPrincipal);
4876
+ if (!context)
4877
+ return;
4878
+ return {
4879
+ context,
4880
+ namespace: await deriveAuthSyncNamespace({
4881
+ clientId: PWA_SYNC_CLIENT_ID,
4882
+ issuer: accessTokens.oidc.issuer,
4883
+ partition: readAuthSyncPartition(authPrincipal.user),
4884
+ subject: authPrincipal.subject
4885
+ })
4886
+ };
4887
+ }
4888
+ });
4889
+
4778
4890
  // src/authContext.ts
4779
4891
  var createAuthContext = ({
4780
4892
  agentAuth,
@@ -4783,19 +4895,27 @@ var createAuthContext = ({
4783
4895
  authorization,
4784
4896
  emit,
4785
4897
  seedSource
4786
- }) => new Elysia8({
4787
- name: "@absolutejs/auth/context",
4788
- seed: pluginDependencySeed(seedSource)
4789
- }).use([
4790
- protectRoutePlugin({ accessTokens, authSessionStore }),
4791
- stepUpPlugin({ authSessionStore }),
4792
- authorization ? protectPermissionPlugin({
4793
- ...authorization,
4794
- authSessionStore,
4795
- emit
4796
- }) : new Elysia8,
4797
- agentAuthContextPlugin(agentAuth)
4798
- ]);
4898
+ }) => {
4899
+ const absoluteAuthSync = accessTokens ? createAbsoluteAuthSyncBridge(accessTokens) : undefined;
4900
+ const syncBridge = new Elysia8({
4901
+ name: "@absolutejs/auth/sync-bridge",
4902
+ seed: pluginDependencySeed(seedSource)
4903
+ }).decorate("absoluteAuthSync", absoluteAuthSync).as("global");
4904
+ return new Elysia8({
4905
+ name: "@absolutejs/auth/context",
4906
+ seed: pluginDependencySeed(seedSource)
4907
+ }).use([
4908
+ syncBridge,
4909
+ protectRoutePlugin({ accessTokens, authSessionStore }),
4910
+ stepUpPlugin({ authSessionStore }),
4911
+ authorization ? protectPermissionPlugin({
4912
+ ...authorization,
4913
+ authSessionStore,
4914
+ emit
4915
+ }) : new Elysia8,
4916
+ agentAuthContextPlugin(agentAuth)
4917
+ ]);
4918
+ };
4799
4919
 
4800
4920
  // src/compliance/routes.ts
4801
4921
  import { Elysia as Elysia9, t as t6 } from "elysia";
@@ -8410,57 +8530,6 @@ var updateRegisteredClient = async ({
8410
8530
 
8411
8531
  // src/oidc/socketTicketRoutes.ts
8412
8532
  import { Elysia as Elysia22, t as t15 } from "elysia";
8413
-
8414
- // src/oidc/socketTickets.ts
8415
- init_crypto();
8416
- var DEFAULT_SOCKET_TICKET_TTL_MS = 30000;
8417
- var TICKET_BYTES = 32;
8418
- var consumeSocketTicket = async ({
8419
- audience,
8420
- getUser,
8421
- now = Date.now(),
8422
- store,
8423
- ticket
8424
- }) => {
8425
- const record = await store.consumeTicket(await hashToken(ticket), now);
8426
- if (!record || record.audience !== audience)
8427
- return;
8428
- const user = await getUser(record.subject);
8429
- if (user === null)
8430
- return;
8431
- return {
8432
- audience: record.audience,
8433
- clientId: record.clientId,
8434
- kind: "access-token",
8435
- scopes: [...record.scopes],
8436
- subject: record.subject,
8437
- user
8438
- };
8439
- };
8440
- var issueSocketTicket = async ({
8441
- audience,
8442
- clientId,
8443
- now = Date.now(),
8444
- scopes,
8445
- store,
8446
- subject,
8447
- ttlMs = DEFAULT_SOCKET_TICKET_TTL_MS
8448
- }) => {
8449
- if (!Number.isFinite(ttlMs) || ttlMs <= 0)
8450
- throw new Error("socketTicketTtlMs must be positive");
8451
- const ticket = `ast_${generateSecureToken(TICKET_BYTES)}`;
8452
- await store.saveTicket({
8453
- audience,
8454
- clientId,
8455
- expiresAt: now + ttlMs,
8456
- scopes: [...scopes],
8457
- subject,
8458
- ticketHash: await hashToken(ticket)
8459
- });
8460
- return { expiresInMs: ttlMs, ticket };
8461
- };
8462
-
8463
- // src/oidc/socketTicketRoutes.ts
8464
8533
  var noStoreJson = (value, status) => new Response(JSON.stringify(value), {
8465
8534
  headers: {
8466
8535
  "cache-control": "no-store",
@@ -40322,6 +40391,7 @@ export {
40322
40391
  readUserInfoBearer,
40323
40392
  readSessionRing,
40324
40393
  readSessionCookie,
40394
+ readAuthSyncPartition,
40325
40395
  pushAuthorizationRequest,
40326
40396
  pruneInactiveUsers,
40327
40397
  providersFromEnv,
@@ -40450,6 +40520,7 @@ export {
40450
40520
  encryptSecret,
40451
40521
  discoverAgentRegistration,
40452
40522
  diffScimGroupMembers,
40523
+ deriveAuthSyncNamespace,
40453
40524
  denyDeviceAuthorization,
40454
40525
  denyBackchannelAuth,
40455
40526
  deleteWarrant,
@@ -40636,6 +40707,7 @@ export {
40636
40707
  createAgentIdentityAssertionVerifier,
40637
40708
  createActionPipeline,
40638
40709
  createAbuseGuard,
40710
+ createAbsoluteAuthSyncBridge,
40639
40711
  consumeSocketTicket,
40640
40712
  consumePushedRequest,
40641
40713
  consumeBackupCode,
@@ -40736,5 +40808,5 @@ export {
40736
40808
  ABSOLUTE_NATIVE_AUTH_CLIENTS_ENV
40737
40809
  };
40738
40810
 
40739
- //# debugId=D50CCD40CF8542E364756E2164756E21
40811
+ //# debugId=C30DB9B5A633F90A64756E2164756E21
40740
40812
  //# sourceMappingURL=index.js.map