@absolutejs/auth 0.56.6 → 0.56.7

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.
@@ -90,6 +90,13 @@ export type OidcProviderConfig<UserType> = {
90
90
  onClientRegistration?: OnClientRegistration;
91
91
  /** Fires after RFC 7591 registration has been persisted and has a generated client id. */
92
92
  onClientRegistered?: OnClientRegistered;
93
+ /** Fires after an authenticated user authorizes an OAuth authorization-code
94
+ * request and the final granted scopes are known, before the code is issued. */
95
+ onAuthorizationCodeApproved?: (context: {
96
+ clientId: string;
97
+ scopes: string[];
98
+ userSub: string;
99
+ }) => void | Promise<void>;
93
100
  /** Fires after the authenticated user approves an RFC 8628 device request. */
94
101
  onDeviceAuthorizationApproved?: (context: {
95
102
  clientId: string;
package/dist/server.js CHANGED
@@ -8193,6 +8193,12 @@ var oidcProviderRoutes = (config) => {
8193
8193
  return errorRedirect("insufficient_user_authentication");
8194
8194
  }
8195
8195
  const code = generateSecureToken(TOKEN_BYTES4);
8196
+ const userSub = getUserId(userSession.user);
8197
+ await config.onAuthorizationCodeApproved?.({
8198
+ clientId: client.clientId,
8199
+ scopes: granted,
8200
+ userSub
8201
+ });
8196
8202
  await authorizationCodeStore.saveCode({
8197
8203
  acr: userAcr,
8198
8204
  audience: effectiveQuery.resource,
@@ -8205,7 +8211,7 @@ var oidcProviderRoutes = (config) => {
8205
8211
  nonce,
8206
8212
  redirectUri,
8207
8213
  scopes: granted,
8208
- userId: getUserId(userSession.user)
8214
+ userId: userSub
8209
8215
  });
8210
8216
  const params = {
8211
8217
  code,
@@ -29448,6 +29454,34 @@ var validatePositiveOptions = (prefix, options) => {
29448
29454
  }
29449
29455
  }
29450
29456
  };
29457
+ var delegateAgentAuthorization = async (agentAuth, context, auditEmit) => {
29458
+ if (agentAuth === undefined)
29459
+ return;
29460
+ const registration2 = await agentAuth.registrationStore.findByClientId(context.clientId);
29461
+ if (registration2 === undefined || registration2.status !== "active")
29462
+ return;
29463
+ const now = Date.now();
29464
+ const existing = await agentAuth.delegationStore.findActiveDelegation({
29465
+ agentId: registration2.agentId,
29466
+ now,
29467
+ userId: context.userSub
29468
+ });
29469
+ await agentAuth.delegationStore.saveDelegation({
29470
+ agentId: registration2.agentId,
29471
+ createdAt: existing?.createdAt ?? now,
29472
+ delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
29473
+ scopes: context.scopes.filter((scope) => registration2.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
29474
+ status: "active",
29475
+ updatedAt: now,
29476
+ userId: context.userSub
29477
+ });
29478
+ await auditEmit?.({
29479
+ at: now,
29480
+ metadata: { agentId: registration2.agentId },
29481
+ type: "agent_delegated",
29482
+ userId: context.userSub
29483
+ });
29484
+ };
29451
29485
  var buildAuthApplications = async (configuration) => {
29452
29486
  const {
29453
29487
  providersConfiguration,
@@ -29571,6 +29605,10 @@ var buildAuthApplications = async (configuration) => {
29571
29605
  }
29572
29606
  return handleAgentTokenGrant(resolvedAgentAuth, context.body);
29573
29607
  },
29608
+ onAuthorizationCodeApproved: async (context) => {
29609
+ await oidc.onAuthorizationCodeApproved?.(context);
29610
+ await delegateAgentAuthorization(agentAuth, context, auditEmit);
29611
+ },
29574
29612
  onClientRegistered: async (context) => {
29575
29613
  await oidc.onClientRegistered?.(context);
29576
29614
  if (agentAuth?.registerDynamicClients !== true)
@@ -29593,33 +29631,7 @@ var buildAuthApplications = async (configuration) => {
29593
29631
  },
29594
29632
  onDeviceAuthorizationApproved: async (context) => {
29595
29633
  await oidc.onDeviceAuthorizationApproved?.(context);
29596
- if (agentAuth === undefined)
29597
- return;
29598
- const registration2 = await agentAuth.registrationStore.findByClientId(context.clientId);
29599
- if (registration2 === undefined || registration2.status !== "active") {
29600
- return;
29601
- }
29602
- const now = Date.now();
29603
- const existing = await agentAuth.delegationStore.findActiveDelegation({
29604
- agentId: registration2.agentId,
29605
- now,
29606
- userId: context.userSub
29607
- });
29608
- await agentAuth.delegationStore.saveDelegation({
29609
- agentId: registration2.agentId,
29610
- createdAt: existing?.createdAt ?? now,
29611
- delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
29612
- scopes: context.scopes.filter((scope) => registration2.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
29613
- status: "active",
29614
- updatedAt: now,
29615
- userId: context.userSub
29616
- });
29617
- await auditEmit?.({
29618
- at: now,
29619
- metadata: { agentId: registration2.agentId },
29620
- type: "agent_delegated",
29621
- userId: context.userSub
29622
- });
29634
+ await delegateAgentAuthorization(agentAuth, context, auditEmit);
29623
29635
  }
29624
29636
  } : undefined;
29625
29637
  const credentialsConfig = credentials ? {
@@ -29792,5 +29804,5 @@ export {
29792
29804
  auth2 as auth
29793
29805
  };
29794
29806
 
29795
- //# debugId=D8EC85FAD0A8B9D564756E2164756E21
29807
+ //# debugId=059E7E401823BC2864756E2164756E21
29796
29808
  //# sourceMappingURL=server.js.map