@absolutejs/auth 0.71.0 → 0.73.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
@@ -17,6 +17,7 @@ export { protectRoutePlugin } from './routes/protectRoute';
17
17
  export { readSessionCookie } from './session/cookieReader';
18
18
  export { requireAuthPlugin } from './routes/requireAuth';
19
19
  export { createAbsoluteAuthSyncBridge, type AbsoluteAuthSyncBridge, type AbsoluteAuthSyncContext } from './syncBridge';
20
+ export { deriveAuthSyncNamespace } from './syncNamespace';
20
21
  export type { ScimConfig } from './scim/config';
21
22
  export type { ScimFilter, ScimGroup, ScimGroupInput, ScimTokenStore, ScimUser, ScimUserInput } from './scim/types';
22
23
  export { createPostgresScimTokenStore } from './scim/postgresScimTokenStore';
package/dist/server.js CHANGED
@@ -5820,8 +5820,35 @@ var issueSocketTicket = async ({
5820
5820
  return { expiresInMs: ttlMs, ticket };
5821
5821
  };
5822
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
+
5823
5848
  // src/syncBridge.ts
5849
+ var PWA_SYNC_CLIENT_ID = "@absolutejs/pwa";
5824
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");
5825
5852
  var createAbsoluteAuthSyncBridge = (accessTokens) => ({
5826
5853
  consumeSocketTicket: async ({ audience, ticket }) => {
5827
5854
  const store = accessTokens.oidc.socketTicketStore;
@@ -5837,7 +5864,23 @@ var createAbsoluteAuthSyncBridge = (accessTokens) => ({
5837
5864
  resolveBearer: async ({ authorization }) => toSyncContext(await resolveAccessTokenPrincipal({
5838
5865
  authorization,
5839
5866
  config: accessTokens
5840
- }))
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
+ }
5841
5884
  });
5842
5885
 
5843
5886
  // src/authContext.ts
@@ -41403,6 +41446,7 @@ export {
41403
41446
  isUserSessionId,
41404
41447
  instantiateUserSession,
41405
41448
  extractPropFromIdentity,
41449
+ deriveAuthSyncNamespace,
41406
41450
  createSetupSession,
41407
41451
  createPostgresSsoConnectionStore,
41408
41452
  createPostgresSetupSessionStore,
@@ -41414,5 +41458,5 @@ export {
41414
41458
  VerificationProviderError
41415
41459
  };
41416
41460
 
41417
- //# debugId=A98DDD902DA1838664756E2164756E21
41461
+ //# debugId=34B819C8B800408C64756E2164756E21
41418
41462
  //# sourceMappingURL=server.js.map