@absolutejs/auth 0.52.0 → 0.53.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
@@ -4868,6 +4868,11 @@ var REFRESH_TTL_DAYS = 30;
4868
4868
  var DEFAULT_ACCESS_TOKEN_TTL_MS2 = MILLISECONDS_IN_AN_HOUR;
4869
4869
  var DEFAULT_ID_TOKEN_TTL_MS = MILLISECONDS_IN_AN_HOUR;
4870
4870
  var DEFAULT_REFRESH_TOKEN_TTL_MS = MILLISECONDS_IN_A_DAY * REFRESH_TTL_DAYS;
4871
+ var resolveAccessTtl = (ttl, scopes) => {
4872
+ if (typeof ttl === "function")
4873
+ return ttl({ scopes });
4874
+ return ttl ?? DEFAULT_ACCESS_TOKEN_TTL_MS2;
4875
+ };
4871
4876
  var nowSeconds = (milliseconds) => Math.floor(milliseconds / MS_PER_SECOND);
4872
4877
  var narrowScopes = (available, requested) => requested === undefined || requested.length === 0 ? available : requested.filter((scope) => available.includes(scope));
4873
4878
  var RESERVED_ACCESS_CLAIMS = new Set([
@@ -4941,7 +4946,7 @@ var exchangeToken = async ({
4941
4946
  return { error: "invalid_scope", ok: false };
4942
4947
  }
4943
4948
  const scopes = narrowScopes(available, requestedScopes);
4944
- const ttl = config.accessTokenTtlMs ?? DEFAULT_ACCESS_TOKEN_TTL_MS2;
4949
+ const ttl = resolveAccessTtl(config.accessTokenTtlMs, scopes);
4945
4950
  const extraClaims = await config.getAccessTokenClaims?.({
4946
4951
  audience,
4947
4952
  clientId: actorClientId,
@@ -4978,7 +4983,7 @@ var issueTokenSet = async ({
4978
4983
  scopes,
4979
4984
  sub
4980
4985
  }) => {
4981
- const accessTtl = config.accessTokenTtlMs ?? DEFAULT_ACCESS_TOKEN_TTL_MS2;
4986
+ const accessTtl = resolveAccessTtl(config.accessTokenTtlMs, scopes);
4982
4987
  const idTtl = config.idTokenTtlMs ?? DEFAULT_ID_TOKEN_TTL_MS;
4983
4988
  const refreshTtl = config.refreshTokenTtlMs ?? DEFAULT_REFRESH_TOKEN_TTL_MS;
4984
4989
  const accessExtra = await config.getAccessTokenClaims?.({
@@ -6435,6 +6440,17 @@ var jsonResponse = (value, status) => new Response(JSON.stringify(value), {
6435
6440
  });
6436
6441
  var oauthError2 = (status, error) => jsonResponse({ error }, status);
6437
6442
  var tokenResponse = (tokens) => jsonResponse(tokens, HTTP_OK2);
6443
+ var canonicalizeRequestUrl = (requestUrl, issuer) => {
6444
+ try {
6445
+ const url = new URL(requestUrl);
6446
+ const base = new URL(issuer);
6447
+ url.protocol = base.protocol;
6448
+ url.host = base.host;
6449
+ return url.toString();
6450
+ } catch {
6451
+ return requestUrl;
6452
+ }
6453
+ };
6438
6454
  var redirectTo = (url) => new Response(null, { headers: { location: url }, status: HTTP_FOUND });
6439
6455
  var escapeHtmlAttr = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;");
6440
6456
  var formPostResponse = (redirectUri, params) => {
@@ -6948,7 +6964,7 @@ var oidcProviderRoutes = (config) => {
6948
6964
  if (wantsSilent) {
6949
6965
  return errorRedirect(userSession === undefined ? "login_required" : "interaction_required");
6950
6966
  }
6951
- return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED2) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
6967
+ return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED2) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(canonicalizeRequestUrl(request.url, issuer))}`);
6952
6968
  }
6953
6969
  const requested = scope === undefined || scope.length === 0 ? client.scopes : scope.split(" ").filter((entry) => client.scopes.includes(entry));
6954
6970
  if (config.consentUrl !== undefined && await config.needsConsent?.({
@@ -6960,7 +6976,7 @@ var oidcProviderRoutes = (config) => {
6960
6976
  user: userSession.user
6961
6977
  }) === true) {
6962
6978
  const consentTarget = new URL(config.consentUrl, issuer);
6963
- consentTarget.searchParams.set("return_to", request.url);
6979
+ consentTarget.searchParams.set("return_to", canonicalizeRequestUrl(request.url, issuer));
6964
6980
  consentTarget.searchParams.set("client_id", client.clientId);
6965
6981
  consentTarget.searchParams.set("client_name", client.name);
6966
6982
  consentTarget.searchParams.set("scope", requested.join(" "));
@@ -28043,5 +28059,5 @@ export {
28043
28059
  AuthIdentityConflictError
28044
28060
  };
28045
28061
 
28046
- //# debugId=1C44E17EB1F4FC5164756E2164756E21
28062
+ //# debugId=1AA6ADB109ED877964756E2164756E21
28047
28063
  //# sourceMappingURL=index.js.map