@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/server.d.ts CHANGED
@@ -16,6 +16,8 @@ export { createPostgresSetupSessionStore } from './portal/postgresSetupSessionSt
16
16
  export { protectRoutePlugin } from './routes/protectRoute';
17
17
  export { readSessionCookie } from './session/cookieReader';
18
18
  export { requireAuthPlugin } from './routes/requireAuth';
19
+ export { createAbsoluteAuthSyncBridge, type AbsoluteAuthSyncBridge, type AbsoluteAuthSyncContext } from './syncBridge';
20
+ export { deriveAuthSyncNamespace } from './syncNamespace';
19
21
  export type { ScimConfig } from './scim/config';
20
22
  export type { ScimFilter, ScimGroup, ScimGroupInput, ScimTokenStore, ScimUser, ScimUserInput } from './scim/types';
21
23
  export { createPostgresScimTokenStore } from './scim/postgresScimTokenStore';
package/dist/server.js CHANGED
@@ -5771,6 +5771,118 @@ var stepUpPlugin = ({
5771
5771
  })
5772
5772
  })).as("global");
5773
5773
 
5774
+ // src/oidc/socketTickets.ts
5775
+ init_crypto();
5776
+ var DEFAULT_SOCKET_TICKET_TTL_MS = 30000;
5777
+ var TICKET_BYTES = 32;
5778
+ var consumeSocketTicket = async ({
5779
+ audience,
5780
+ getUser,
5781
+ now = Date.now(),
5782
+ store,
5783
+ ticket
5784
+ }) => {
5785
+ const record = await store.consumeTicket(await hashToken(ticket), now);
5786
+ if (!record || record.audience !== audience)
5787
+ return;
5788
+ const user = await getUser(record.subject);
5789
+ if (user === null)
5790
+ return;
5791
+ return {
5792
+ audience: record.audience,
5793
+ clientId: record.clientId,
5794
+ kind: "access-token",
5795
+ scopes: [...record.scopes],
5796
+ subject: record.subject,
5797
+ user
5798
+ };
5799
+ };
5800
+ var issueSocketTicket = async ({
5801
+ audience,
5802
+ clientId,
5803
+ now = Date.now(),
5804
+ scopes,
5805
+ store,
5806
+ subject,
5807
+ ttlMs = DEFAULT_SOCKET_TICKET_TTL_MS
5808
+ }) => {
5809
+ if (!Number.isFinite(ttlMs) || ttlMs <= 0)
5810
+ throw new Error("socketTicketTtlMs must be positive");
5811
+ const ticket = `ast_${generateSecureToken(TICKET_BYTES)}`;
5812
+ await store.saveTicket({
5813
+ audience,
5814
+ clientId,
5815
+ expiresAt: now + ttlMs,
5816
+ scopes: [...scopes],
5817
+ subject,
5818
+ ticketHash: await hashToken(ticket)
5819
+ });
5820
+ return { expiresInMs: ttlMs, ticket };
5821
+ };
5822
+
5823
+ // src/syncNamespace.ts
5824
+ var base64Url2 = (value) => {
5825
+ let binary = "";
5826
+ for (const byte of value)
5827
+ binary += String.fromCharCode(byte);
5828
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
5829
+ };
5830
+ var deriveAuthSyncNamespace = async ({
5831
+ clientId,
5832
+ issuer,
5833
+ partition,
5834
+ subject
5835
+ }) => {
5836
+ if (clientId.length === 0 || issuer.length === 0 || subject.length === 0)
5837
+ throw new TypeError("Auth Sync namespace requires issuer, clientId, and subject.");
5838
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify([issuer, clientId, subject, partition ?? null])));
5839
+ return `auth:v1:${base64Url2(new Uint8Array(digest))}`;
5840
+ };
5841
+ var readAuthSyncPartition = (user) => {
5842
+ if (typeof user !== "object" || user === null)
5843
+ return;
5844
+ const value = Reflect.get(user, "absolutejs_sync_partition");
5845
+ return typeof value === "string" && value.length > 0 ? value : undefined;
5846
+ };
5847
+
5848
+ // src/syncBridge.ts
5849
+ var PWA_SYNC_CLIENT_ID = "@absolutejs/pwa";
5850
+ var toSyncContext = (authPrincipal) => authPrincipal ? { authPrincipal, user: authPrincipal.user } : undefined;
5851
+ 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");
5852
+ var createAbsoluteAuthSyncBridge = (accessTokens) => ({
5853
+ consumeSocketTicket: async ({ audience, ticket }) => {
5854
+ const store = accessTokens.oidc.socketTicketStore;
5855
+ if (!store)
5856
+ return;
5857
+ return toSyncContext(await consumeSocketTicket({
5858
+ audience: audience ?? accessTokens.oidc.issuer,
5859
+ getUser: accessTokens.getUser,
5860
+ store,
5861
+ ticket
5862
+ }));
5863
+ },
5864
+ resolveBearer: async ({ authorization }) => toSyncContext(await resolveAccessTokenPrincipal({
5865
+ authorization,
5866
+ config: accessTokens
5867
+ })),
5868
+ resolveSession: async ({ authPrincipal }) => {
5869
+ if (!isSessionAuthPrincipal(authPrincipal))
5870
+ return;
5871
+ const context = toSyncContext(authPrincipal);
5872
+ if (!context)
5873
+ return;
5874
+ return {
5875
+ context,
5876
+ namespace: await deriveAuthSyncNamespace({
5877
+ clientId: PWA_SYNC_CLIENT_ID,
5878
+ issuer: accessTokens.oidc.issuer,
5879
+ partition: readAuthSyncPartition(authPrincipal.user),
5880
+ subject: authPrincipal.subject
5881
+ })
5882
+ };
5883
+ }
5884
+ });
5885
+
5774
5886
  // src/authContext.ts
5775
5887
  var createAuthContext = ({
5776
5888
  agentAuth,
@@ -5779,19 +5891,27 @@ var createAuthContext = ({
5779
5891
  authorization,
5780
5892
  emit,
5781
5893
  seedSource
5782
- }) => new Elysia8({
5783
- name: "@absolutejs/auth/context",
5784
- seed: pluginDependencySeed(seedSource)
5785
- }).use([
5786
- protectRoutePlugin({ accessTokens, authSessionStore }),
5787
- stepUpPlugin({ authSessionStore }),
5788
- authorization ? protectPermissionPlugin({
5789
- ...authorization,
5790
- authSessionStore,
5791
- emit
5792
- }) : new Elysia8,
5793
- agentAuthContextPlugin(agentAuth)
5794
- ]);
5894
+ }) => {
5895
+ const absoluteAuthSync = accessTokens ? createAbsoluteAuthSyncBridge(accessTokens) : undefined;
5896
+ const syncBridge = new Elysia8({
5897
+ name: "@absolutejs/auth/sync-bridge",
5898
+ seed: pluginDependencySeed(seedSource)
5899
+ }).decorate("absoluteAuthSync", absoluteAuthSync).as("global");
5900
+ return new Elysia8({
5901
+ name: "@absolutejs/auth/context",
5902
+ seed: pluginDependencySeed(seedSource)
5903
+ }).use([
5904
+ syncBridge,
5905
+ protectRoutePlugin({ accessTokens, authSessionStore }),
5906
+ stepUpPlugin({ authSessionStore }),
5907
+ authorization ? protectPermissionPlugin({
5908
+ ...authorization,
5909
+ authSessionStore,
5910
+ emit
5911
+ }) : new Elysia8,
5912
+ agentAuthContextPlugin(agentAuth)
5913
+ ]);
5914
+ };
5795
5915
 
5796
5916
  // src/compliance/routes.ts
5797
5917
  import { Elysia as Elysia9, t as t6 } from "elysia";
@@ -9406,57 +9526,6 @@ var updateRegisteredClient = async ({
9406
9526
 
9407
9527
  // src/oidc/socketTicketRoutes.ts
9408
9528
  import { Elysia as Elysia22, t as t15 } from "elysia";
9409
-
9410
- // src/oidc/socketTickets.ts
9411
- init_crypto();
9412
- var DEFAULT_SOCKET_TICKET_TTL_MS = 30000;
9413
- var TICKET_BYTES = 32;
9414
- var consumeSocketTicket = async ({
9415
- audience,
9416
- getUser,
9417
- now = Date.now(),
9418
- store,
9419
- ticket
9420
- }) => {
9421
- const record = await store.consumeTicket(await hashToken(ticket), now);
9422
- if (!record || record.audience !== audience)
9423
- return;
9424
- const user = await getUser(record.subject);
9425
- if (user === null)
9426
- return;
9427
- return {
9428
- audience: record.audience,
9429
- clientId: record.clientId,
9430
- kind: "access-token",
9431
- scopes: [...record.scopes],
9432
- subject: record.subject,
9433
- user
9434
- };
9435
- };
9436
- var issueSocketTicket = async ({
9437
- audience,
9438
- clientId,
9439
- now = Date.now(),
9440
- scopes,
9441
- store,
9442
- subject,
9443
- ttlMs = DEFAULT_SOCKET_TICKET_TTL_MS
9444
- }) => {
9445
- if (!Number.isFinite(ttlMs) || ttlMs <= 0)
9446
- throw new Error("socketTicketTtlMs must be positive");
9447
- const ticket = `ast_${generateSecureToken(TICKET_BYTES)}`;
9448
- await store.saveTicket({
9449
- audience,
9450
- clientId,
9451
- expiresAt: now + ttlMs,
9452
- scopes: [...scopes],
9453
- subject,
9454
- ticketHash: await hashToken(ticket)
9455
- });
9456
- return { expiresInMs: ttlMs, ticket };
9457
- };
9458
-
9459
- // src/oidc/socketTicketRoutes.ts
9460
9529
  var noStoreJson = (value, status) => new Response(JSON.stringify(value), {
9461
9530
  headers: {
9462
9531
  "cache-control": "no-store",
@@ -41377,15 +41446,17 @@ export {
41377
41446
  isUserSessionId,
41378
41447
  instantiateUserSession,
41379
41448
  extractPropFromIdentity,
41449
+ deriveAuthSyncNamespace,
41380
41450
  createSetupSession,
41381
41451
  createPostgresSsoConnectionStore,
41382
41452
  createPostgresSetupSessionStore,
41383
41453
  createPostgresScimTokenStore,
41384
41454
  createNodeSamlAdapter,
41385
41455
  createAuthContext,
41456
+ createAbsoluteAuthSyncBridge,
41386
41457
  auth2 as auth,
41387
41458
  VerificationProviderError
41388
41459
  };
41389
41460
 
41390
- //# debugId=09854CD88815EF0764756E2164756E21
41461
+ //# debugId=34B819C8B800408C64756E2164756E21
41391
41462
  //# sourceMappingURL=server.js.map