@absolutejs/auth 0.55.1 → 0.55.2

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.
@@ -201,8 +201,8 @@ export declare const oidcProviderRoutes: <UserType>(config: OidcProviderConfig<U
201
201
  body: {
202
202
  client_id?: string | undefined;
203
203
  scope?: string | undefined;
204
- login_hint?: string | undefined;
205
204
  client_secret?: string | undefined;
205
+ login_hint?: string | undefined;
206
206
  binding_message?: string | undefined;
207
207
  };
208
208
  params: {};
package/dist/server.js CHANGED
@@ -3044,9 +3044,6 @@ var apiKeysRoutes = ({
3044
3044
  });
3045
3045
  };
3046
3046
 
3047
- // src/agents/routes.ts
3048
- import { Elysia as Elysia2 } from "elysia";
3049
-
3050
3047
  // src/agents/config.ts
3051
3048
  var DEFAULT_AGENT_RESOURCE_METADATA_ROUTE = "/.well-known/oauth-protected-resource";
3052
3049
  var agentProtectedResourceMetadata = (config) => ({
@@ -3058,6 +3055,9 @@ var agentProtectedResourceMetadata = (config) => ({
3058
3055
  scopes_supported: config.scopes
3059
3056
  });
3060
3057
 
3058
+ // src/agents/context.ts
3059
+ import { Elysia as Elysia2 } from "elysia";
3060
+
3061
3061
  // src/agents/principal.ts
3062
3062
  var intersectScopes = (...sets) => {
3063
3063
  if (sets.length === 0)
@@ -3112,6 +3112,77 @@ var resolveAgentPrincipal = async (request, config) => {
3112
3112
  };
3113
3113
  };
3114
3114
 
3115
+ // src/agents/context.ts
3116
+ var DELETE_CODE_POINT = 127;
3117
+ var HTTP_FORBIDDEN = 403;
3118
+ var HTTP_UNAUTHORIZED2 = 401;
3119
+ var MINIMUM_PRINTABLE_CODE_POINT = 32;
3120
+ var quoteHeaderValue = (value) => {
3121
+ const printable = [...value].filter((character) => {
3122
+ const codePoint = character.codePointAt(0) ?? 0;
3123
+ return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
3124
+ }).join("");
3125
+ return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
3126
+ };
3127
+ var agentAuthChallenge = ({
3128
+ config,
3129
+ error,
3130
+ requiredScopes = []
3131
+ }) => {
3132
+ const parameters = [
3133
+ `resource_metadata=${quoteHeaderValue(agentResourceMetadataUrl(config))}`
3134
+ ];
3135
+ if (requiredScopes.length > 0) {
3136
+ parameters.push(`scope=${quoteHeaderValue(requiredScopes.join(" "))}`);
3137
+ }
3138
+ if (error !== undefined) {
3139
+ parameters.push(`error=${quoteHeaderValue(error)}`);
3140
+ }
3141
+ return `Bearer ${parameters.join(", ")}`;
3142
+ };
3143
+ var agentResourceMetadataUrl = (config) => new URL(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, config.resource).toString();
3144
+ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.stringify({
3145
+ error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3146
+ error_description: failure.message
3147
+ }), {
3148
+ headers: {
3149
+ "content-type": "application/json",
3150
+ "www-authenticate": agentAuthChallenge({
3151
+ config,
3152
+ error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3153
+ requiredScopes
3154
+ })
3155
+ },
3156
+ status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED2
3157
+ });
3158
+ var agentAuthContextPlugin = (config) => new Elysia2().derive(({ request }) => ({
3159
+ protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
3160
+ if (config === undefined) {
3161
+ const failure = {
3162
+ code: "Unauthorized",
3163
+ message: "Agent is not authenticated"
3164
+ };
3165
+ return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: HTTP_UNAUTHORIZED2 });
3166
+ }
3167
+ const principal = await resolveAgentPrincipal(request, config);
3168
+ if (principal === undefined) {
3169
+ const failure = {
3170
+ code: "Unauthorized",
3171
+ message: "Agent is not authenticated"
3172
+ };
3173
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3174
+ }
3175
+ if (!agentHasScopes(principal, requiredScopes)) {
3176
+ const failure = {
3177
+ code: "Forbidden",
3178
+ message: "Insufficient agent scopes"
3179
+ };
3180
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3181
+ }
3182
+ return handleAuth(principal);
3183
+ }
3184
+ }));
3185
+
3115
3186
  // src/agents/registration.ts
3116
3187
  init_constants();
3117
3188
  init_crypto();
@@ -3780,50 +3851,9 @@ var revokeAgentIdentityRegistration = async (config, registrationId, now = Date.
3780
3851
  };
3781
3852
 
3782
3853
  // src/agents/routes.ts
3783
- var DELETE_CODE_POINT = 127;
3784
3854
  var HTTP_BAD_REQUEST2 = 400;
3785
- var HTTP_FORBIDDEN = 403;
3786
3855
  var HTTP_OK2 = 200;
3787
- var HTTP_UNAUTHORIZED2 = 401;
3788
- var MINIMUM_PRINTABLE_CODE_POINT = 32;
3789
- var quoteHeaderValue = (value) => {
3790
- const printable = [...value].filter((character) => {
3791
- const codePoint = character.codePointAt(0) ?? 0;
3792
- return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
3793
- }).join("");
3794
- return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
3795
- };
3796
- var agentAuthChallenge = ({
3797
- config,
3798
- error,
3799
- requiredScopes = []
3800
- }) => {
3801
- const parameters = [
3802
- `resource_metadata=${quoteHeaderValue(agentResourceMetadataUrl(config))}`
3803
- ];
3804
- if (requiredScopes.length > 0) {
3805
- parameters.push(`scope=${quoteHeaderValue(requiredScopes.join(" "))}`);
3806
- }
3807
- if (error !== undefined) {
3808
- parameters.push(`error=${quoteHeaderValue(error)}`);
3809
- }
3810
- return `Bearer ${parameters.join(", ")}`;
3811
- };
3812
- var agentResourceMetadataUrl = (config) => new URL(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, config.resource).toString();
3813
- var failureResponse = (config, failure, requiredScopes) => new Response(JSON.stringify({
3814
- error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3815
- error_description: failure.message
3816
- }), {
3817
- headers: {
3818
- "content-type": "application/json",
3819
- "www-authenticate": agentAuthChallenge({
3820
- config,
3821
- error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3822
- requiredScopes
3823
- })
3824
- },
3825
- status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED2
3826
- });
3856
+ var HTTP_UNAUTHORIZED3 = 401;
3827
3857
  var json = (value, status = HTTP_OK2) => new Response(JSON.stringify(value), {
3828
3858
  headers: {
3829
3859
  "cache-control": "no-store",
@@ -3858,7 +3888,7 @@ var registrationResponse = (result) => {
3858
3888
  ...body,
3859
3889
  error: "interaction_required",
3860
3890
  error_description: "Authenticate at the service and confirm the account link."
3861
- }, HTTP_UNAUTHORIZED2);
3891
+ }, HTTP_UNAUTHORIZED3);
3862
3892
  }
3863
3893
  return json(body);
3864
3894
  };
@@ -3885,33 +3915,6 @@ var parseRegistrationInput = (value) => {
3885
3915
  return input;
3886
3916
  };
3887
3917
  var escapeHtml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
3888
- var agentAuthContextPlugin = (config) => new Elysia2().derive(({ request }) => ({
3889
- protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
3890
- if (config === undefined) {
3891
- const failure = {
3892
- code: "Unauthorized",
3893
- message: "Agent is not authenticated"
3894
- };
3895
- return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
3896
- }
3897
- const principal = await resolveAgentPrincipal(request, config);
3898
- if (principal === undefined) {
3899
- const failure = {
3900
- code: "Unauthorized",
3901
- message: "Agent is not authenticated"
3902
- };
3903
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3904
- }
3905
- if (!agentHasScopes(principal, requiredScopes)) {
3906
- const failure = {
3907
- code: "Forbidden",
3908
- message: "Insufficient agent scopes"
3909
- };
3910
- return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3911
- }
3912
- return handleAuth(principal);
3913
- }
3914
- }));
3915
3918
  var agentAuthPlugin = (config) => {
3916
3919
  const plugin = agentAuthContextPlugin(config);
3917
3920
  if (config === undefined)
@@ -7460,7 +7463,7 @@ var HTTP_OK3 = 200;
7460
7463
  var HTTP_NO_CONTENT = 204;
7461
7464
  var HTTP_FOUND = 302;
7462
7465
  var HTTP_BAD_REQUEST3 = 400;
7463
- var HTTP_UNAUTHORIZED3 = 401;
7466
+ var HTTP_UNAUTHORIZED4 = 401;
7464
7467
  var HTTP_NOT_IMPLEMENTED = 501;
7465
7468
  var CODE_TTL_MINUTES = 10;
7466
7469
  var CODE_TTL_MS = MILLISECONDS_IN_A_MINUTE * CODE_TTL_MINUTES;
@@ -7634,7 +7637,7 @@ var oidcProviderRoutes = (config) => {
7634
7637
  "dpop-nonce": fresh,
7635
7638
  "www-authenticate": 'DPoP error="use_dpop_nonce"'
7636
7639
  },
7637
- status: HTTP_UNAUTHORIZED3
7640
+ status: HTTP_UNAUTHORIZED4
7638
7641
  });
7639
7642
  };
7640
7643
  const grantAuthorizationCode = async (client, body, dpop, clientCertThumbprint) => {
@@ -8010,7 +8013,7 @@ var oidcProviderRoutes = (config) => {
8010
8013
  if (wantsSilent) {
8011
8014
  return errorRedirect(userSession === undefined ? "login_required" : "interaction_required");
8012
8015
  }
8013
- return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED3) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(canonicalizeRequestUrl(request.url, issuer))}`);
8016
+ return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED4) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(canonicalizeRequestUrl(request.url, issuer))}`);
8014
8017
  }
8015
8018
  const requested = scope === undefined || scope.length === 0 ? client.scopes : scope.split(" ").filter((entry) => client.scopes.includes(entry));
8016
8019
  if (config.consentUrl !== undefined && await config.needsConsent?.({
@@ -8131,7 +8134,7 @@ var oidcProviderRoutes = (config) => {
8131
8134
  requestHeaders: request.headers
8132
8135
  });
8133
8136
  if (auth === undefined) {
8134
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8137
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8135
8138
  }
8136
8139
  const { client, clientCertThumbprint } = auth;
8137
8140
  const nonceChallenge = await dpopNonceChallenge(headers.dpop);
@@ -8190,7 +8193,7 @@ var oidcProviderRoutes = (config) => {
8190
8193
  requestHeaders: request.headers
8191
8194
  });
8192
8195
  if (auth === undefined) {
8193
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8196
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8194
8197
  }
8195
8198
  const { client } = auth;
8196
8199
  const isAuthField = (key) => key === "client_assertion" || key === "client_assertion_type" || key === "client_secret";
@@ -8228,11 +8231,11 @@ var oidcProviderRoutes = (config) => {
8228
8231
  const clientId = body.client_id ?? basic.clientId;
8229
8232
  const clientSecret = body.client_secret ?? basic.clientSecret;
8230
8233
  if (clientId === undefined) {
8231
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8234
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8232
8235
  }
8233
8236
  const client = await authenticateClient(clientId, clientSecret);
8234
8237
  if (client === undefined) {
8235
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8238
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8236
8239
  }
8237
8240
  const result = await introspectToken({
8238
8241
  config,
@@ -8256,11 +8259,11 @@ var oidcProviderRoutes = (config) => {
8256
8259
  const clientId = body.client_id ?? basic.clientId;
8257
8260
  const clientSecret = body.client_secret ?? basic.clientSecret;
8258
8261
  if (clientId === undefined) {
8259
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8262
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8260
8263
  }
8261
8264
  const client = await authenticateClient(clientId, clientSecret);
8262
8265
  if (client === undefined) {
8263
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8266
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8264
8267
  }
8265
8268
  if (body.token_type_hint !== "access_token") {
8266
8269
  await revokeRefreshToken(config, body.token);
@@ -8284,11 +8287,11 @@ var oidcProviderRoutes = (config) => {
8284
8287
  const clientId = body.client_id ?? basic.clientId;
8285
8288
  const clientSecret = body.client_secret ?? basic.clientSecret;
8286
8289
  if (clientId === undefined) {
8287
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8290
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8288
8291
  }
8289
8292
  const client = await authenticateClient(clientId, clientSecret);
8290
8293
  if (client === undefined) {
8291
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8294
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8292
8295
  }
8293
8296
  if (body.login_hint === undefined) {
8294
8297
  return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
@@ -8328,11 +8331,11 @@ var oidcProviderRoutes = (config) => {
8328
8331
  const clientId = body.client_id ?? basic.clientId;
8329
8332
  const clientSecret = body.client_secret ?? basic.clientSecret;
8330
8333
  if (clientId === undefined) {
8331
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8334
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8332
8335
  }
8333
8336
  const client = await authenticateClient(clientId, clientSecret);
8334
8337
  if (client === undefined) {
8335
- return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
8338
+ return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
8336
8339
  }
8337
8340
  const requested = body.scope === undefined || body.scope.length === 0 ? client.scopes : body.scope.split(" ").filter((entry) => client.scopes.includes(entry));
8338
8341
  const response = await issueDeviceAuthorization({
@@ -8361,7 +8364,7 @@ var oidcProviderRoutes = (config) => {
8361
8364
  userSessionId: user_session_id.value
8362
8365
  });
8363
8366
  if (userSession === undefined) {
8364
- return oauthError2(HTTP_UNAUTHORIZED3, "login_required");
8367
+ return oauthError2(HTTP_UNAUTHORIZED4, "login_required");
8365
8368
  }
8366
8369
  const result = body.action === "deny" ? await denyDeviceAuthorization({
8367
8370
  config,
@@ -8512,7 +8515,7 @@ var oidcProviderRoutes = (config) => {
8512
8515
  "content-type": "application/json",
8513
8516
  "www-authenticate": userInfoChallengeHeader(result.error)
8514
8517
  },
8515
- status: HTTP_UNAUTHORIZED3
8518
+ status: HTTP_UNAUTHORIZED4
8516
8519
  });
8517
8520
  }
8518
8521
  return jsonResponse(result.body, HTTP_OK3);
@@ -8529,7 +8532,7 @@ var oidcProviderRoutes = (config) => {
8529
8532
  "content-type": "application/json",
8530
8533
  "www-authenticate": userInfoChallengeHeader(result.error)
8531
8534
  },
8532
- status: HTTP_UNAUTHORIZED3
8535
+ status: HTTP_UNAUTHORIZED4
8533
8536
  });
8534
8537
  }
8535
8538
  return jsonResponse(result.body, HTTP_OK3);
@@ -25052,7 +25055,7 @@ var createInMemoryCredentialOfferStore = () => {
25052
25055
  import { Elysia as Elysia38, t as t33 } from "elysia";
25053
25056
  var HTTP_OK4 = 200;
25054
25057
  var HTTP_BAD_REQUEST4 = 400;
25055
- var HTTP_UNAUTHORIZED4 = 401;
25058
+ var HTTP_UNAUTHORIZED5 = 401;
25056
25059
  var BEARER_PREFIX5 = "Bearer ";
25057
25060
  var errorBody = (error, status) => new Response(JSON.stringify({ error }), {
25058
25061
  headers: { "content-type": "application/json" },
@@ -25081,7 +25084,7 @@ var vciRoutes = ({
25081
25084
  }))).post(credentialRoute, async ({ body, headers }) => {
25082
25085
  const accessToken = extractBearer(headers.authorization);
25083
25086
  if (accessToken === undefined) {
25084
- return errorBody("invalid_token", HTTP_UNAUTHORIZED4);
25087
+ return errorBody("invalid_token", HTTP_UNAUTHORIZED5);
25085
25088
  }
25086
25089
  const result = await issueCredential({
25087
25090
  config: vciConfig,
@@ -28652,7 +28655,7 @@ var blockMigrations = {
28652
28655
  // src/sso/samlIdpRoutes.ts
28653
28656
  import { Elysia as Elysia41, t as t36 } from "elysia";
28654
28657
  var HTTP_BAD_REQUEST6 = 400;
28655
- var HTTP_UNAUTHORIZED5 = 401;
28658
+ var HTTP_UNAUTHORIZED6 = 401;
28656
28659
  var HTTP_FOUND2 = 302;
28657
28660
  var HTTP_OK7 = 200;
28658
28661
  var xmlResponse = (body) => new Response(body, {
@@ -28748,7 +28751,7 @@ var samlIdpRoutes = ({
28748
28751
  });
28749
28752
  if (userSession === undefined || parsed.forceAuthn === true) {
28750
28753
  if (loginUrl === undefined) {
28751
- return errorJson(HTTP_UNAUTHORIZED5, "login_required");
28754
+ return errorJson(HTTP_UNAUTHORIZED6, "login_required");
28752
28755
  }
28753
28756
  return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
28754
28757
  }
@@ -28813,7 +28816,7 @@ var samlIdpRoutes = ({
28813
28816
  });
28814
28817
  if (userSession === undefined) {
28815
28818
  if (loginUrl === undefined) {
28816
- return errorJson(HTTP_UNAUTHORIZED5, "login_required");
28819
+ return errorJson(HTTP_UNAUTHORIZED6, "login_required");
28817
28820
  }
28818
28821
  return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
28819
28822
  }
@@ -29358,5 +29361,5 @@ export {
29358
29361
  auth2 as auth
29359
29362
  };
29360
29363
 
29361
- //# debugId=D6C26946999A57D364756E2164756E21
29364
+ //# debugId=1844495EF9D2CC3164756E2164756E21
29362
29365
  //# sourceMappingURL=server.js.map