@absolutejs/auth 0.54.3 → 0.54.5

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
@@ -1946,6 +1946,7 @@ var providers = defineProviders({
1946
1946
  }
1947
1947
  },
1948
1948
  withings: {
1949
+ accessTokenPath: ["body", "access_token"],
1949
1950
  authorizationUrl: "https://account.withings.com/oauth2_user/authorize2",
1950
1951
  isOIDC: false,
1951
1952
  isRefreshable: true,
@@ -2800,10 +2801,21 @@ var buildOAuth2Client = async (meta, config) => {
2800
2801
  if (!response.ok)
2801
2802
  throw await createOAuth2FetchError(response);
2802
2803
  const tokenResponse = await response.json();
2804
+ if (!tokenResponse || typeof tokenResponse !== "object") {
2805
+ throw new Error("OAuth token endpoint returned a non-object response");
2806
+ }
2807
+ const oauthError = Reflect.get(tokenResponse, "error");
2808
+ if (typeof oauthError === "string" && oauthError.length > 0) {
2809
+ throw new Error(`OAuth token exchange failed: ${oauthError}`);
2810
+ }
2803
2811
  const nestedToken = meta.accessTokenPath ? readPath(tokenResponse, meta.accessTokenPath) : undefined;
2804
2812
  if (typeof nestedToken === "string" && nestedToken.length > 0 && tokenResponse && typeof tokenResponse === "object") {
2805
2813
  tokenResponse.access_token = nestedToken;
2806
2814
  }
2815
+ const accessToken = Reflect.get(tokenResponse, "access_token");
2816
+ if (typeof accessToken !== "string" || accessToken.length === 0) {
2817
+ throw new Error("OAuth token endpoint returned no access_token");
2818
+ }
2807
2819
  return tokenResponse;
2808
2820
  }
2809
2821
  };
@@ -3427,6 +3439,18 @@ var resolveOAuthAuthorization = async ({
3427
3439
  let userIdentity;
3428
3440
  let accessToken = tokenResponse.access_token;
3429
3441
  let refreshToken = tokenResponse.refresh_token;
3442
+ if (authProvider === "withings" && !accessToken) {
3443
+ const body = Reflect.get(tokenResponse, "body");
3444
+ if (body && typeof body === "object") {
3445
+ const nestedAccessToken = Reflect.get(body, "access_token");
3446
+ if (typeof nestedAccessToken === "string") {
3447
+ accessToken = nestedAccessToken;
3448
+ }
3449
+ }
3450
+ }
3451
+ if (typeof accessToken !== "string" || accessToken.length === 0) {
3452
+ throw new Error("OAuth authorization response contains no access_token");
3453
+ }
3430
3454
  if (tokenResponse.id_token) {
3431
3455
  userIdentity = normalizeProviderIdentity({
3432
3456
  identity: decodeJWT(tokenResponse.id_token),
@@ -3445,7 +3469,7 @@ var resolveOAuthAuthorization = async ({
3445
3469
  refreshToken = tokenResponse.body.refresh_token;
3446
3470
  } else {
3447
3471
  userIdentity = normalizeProviderIdentity({
3448
- identity: await providerInstance.fetchUserProfile(tokenResponse.access_token),
3472
+ identity: await providerInstance.fetchUserProfile(accessToken),
3449
3473
  providerConfiguration: meta,
3450
3474
  source: "profile"
3451
3475
  });
@@ -9245,6 +9269,18 @@ var stepUpPlugin = ({
9245
9269
 
9246
9270
  // src/routes/signout.ts
9247
9271
  import { Elysia as Elysia29, t as t26 } from "elysia";
9272
+ var sessionForSignOut = ({
9273
+ authSessionStore,
9274
+ currentSession,
9275
+ session,
9276
+ userSessionId
9277
+ }) => {
9278
+ if (!authSessionStore)
9279
+ return session;
9280
+ if (!currentSession)
9281
+ return {};
9282
+ return { [userSessionId]: currentSession };
9283
+ };
9248
9284
  var runSignOut = async (onSignOut, args) => {
9249
9285
  try {
9250
9286
  await onSignOut?.(args);
@@ -9274,7 +9310,12 @@ var signout = ({
9274
9310
  return status("Unauthorized", "No user session id found");
9275
9311
  }
9276
9312
  const currentSession = authSessionStore ? await authSessionStore.getSession(user_session_id.value) : session[user_session_id.value];
9277
- const signoutSession = currentSession === undefined ? {} : { [user_session_id.value]: currentSession };
9313
+ const signoutSession = sessionForSignOut({
9314
+ authSessionStore,
9315
+ currentSession,
9316
+ session,
9317
+ userSessionId: user_session_id.value
9318
+ });
9278
9319
  if (currentSession !== undefined) {
9279
9320
  const signedOut = await runSignOut(onSignOut, {
9280
9321
  authProvider: auth_provider?.value,
@@ -27928,5 +27969,5 @@ export {
27928
27969
  AuthIdentityConflictError
27929
27970
  };
27930
27971
 
27931
- //# debugId=8FD44B77059462F264756E2164756E21
27972
+ //# debugId=D2040C8440D411EC64756E2164756E21
27932
27973
  //# sourceMappingURL=index.js.map