@absolutejs/auth 0.54.4 → 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
  });
@@ -27945,5 +27969,5 @@ export {
27945
27969
  AuthIdentityConflictError
27946
27970
  };
27947
27971
 
27948
- //# debugId=3641271C853CFF2564756E2164756E21
27972
+ //# debugId=D2040C8440D411EC64756E2164756E21
27949
27973
  //# sourceMappingURL=index.js.map