@assinafy/cli 2.3.0 → 2.4.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/api.js CHANGED
@@ -1137,6 +1137,9 @@ function validationConfig(signerAccessCode) {
1137
1137
 
1138
1138
  // src/api/resources/oauth.ts
1139
1139
  import { createHash, randomBytes, timingSafeEqual } from "crypto";
1140
+ var formRequestConfig = publicRequestConfig({
1141
+ headers: { "Content-Type": "application/x-www-form-urlencoded" }
1142
+ });
1140
1143
  var OAuthResource = class extends BaseResource {
1141
1144
  /** `GET /.well-known/oauth-protected-resource` at the API origin, outside `/v1`. */
1142
1145
  async metadata() {
@@ -1249,7 +1252,10 @@ var OAuthResource = class extends BaseResource {
1249
1252
  resource: request.resource
1250
1253
  });
1251
1254
  }
1252
- /** `POST /oauth/token` — code exchange or refresh; returns the flat OAuth JSON body. */
1255
+ /**
1256
+ * `POST /oauth/token` — code exchange or refresh; returns the flat OAuth JSON body.
1257
+ * A refresh must return a new `refresh_token`; otherwise this throws `ValidationError`.
1258
+ */
1253
1259
  async token(payload) {
1254
1260
  required(payload.client_id, "client_id");
1255
1261
  if (payload.client_secret !== void 0) required(payload.client_secret, "client_secret");
@@ -1267,10 +1273,18 @@ var OAuthResource = class extends BaseResource {
1267
1273
  } else {
1268
1274
  throw new ValidationError("grant_type must be authorization_code or refresh_token");
1269
1275
  }
1270
- return this.call(
1276
+ const tokens = await this.call(
1271
1277
  "OAuth token request failed",
1272
- () => this.http.post("/oauth/token", payload, publicRequestConfig())
1278
+ () => this.http.post("/oauth/token", payload, formRequestConfig)
1273
1279
  );
1280
+ const next = tokens?.refresh_token;
1281
+ if (payload.grant_type === "refresh_token" && (typeof next !== "string" || !next.trim() || next === payload.refresh_token)) {
1282
+ throw new ValidationError(
1283
+ "OAuth refresh response has no new refresh_token; the submitted refresh token may already be retired, so do not reuse it: reconnect instead",
1284
+ { field: "refresh_token" }
1285
+ );
1286
+ }
1287
+ return tokens;
1274
1288
  }
1275
1289
  /** `POST /oauth/revoke` — revoke an access/refresh token; success has no required body. */
1276
1290
  async revoke(payload) {
@@ -1282,7 +1296,7 @@ var OAuthResource = class extends BaseResource {
1282
1296
  }
1283
1297
  await this.call(
1284
1298
  "OAuth revocation failed",
1285
- () => this.http.post("/oauth/revoke", payload, publicRequestConfig())
1299
+ () => this.http.post("/oauth/revoke", payload, formRequestConfig)
1286
1300
  );
1287
1301
  }
1288
1302
  /** `GET /oauth/userinfo` — flat OIDC claims; requires a bearer token with `openid`. */