@thunderid/browser 1.16.0 → 1.18.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.
@@ -73,6 +73,10 @@ declare class BackendClient {
73
73
  * success the cached session is dropped, so the next read returns the unit's; on a refusal the
74
74
  * session stays as it was.
75
75
  *
76
+ * The unit goes in the query (`ouId`) and in a JSON body (`{"ouId": …}`), so a backend can read it
77
+ * from either. A `401` left after the refresh means the backend has no session to switch, so it is
78
+ * reported as `login_required` whatever its body says.
79
+ *
76
80
  * @returns The refusal, with the backend's OAuth `error` when it sent one, or `undefined` on success.
77
81
  */
78
82
  switchOrganizationUnit(ouId: string): Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"BackendClient.d.ts","sourceRoot":"","sources":["../src/BackendClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,cAAc,EAAE,wBAAwB,EAAE,WAAW,EAAyB,MAAM,uBAAuB,CAAC;AAEpH;;;GAGG;AACH,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAOzD;;;GAGG;AACH,cAAM,aAAa;IAcL,OAAO,CAAC,QAAQ,CAAC,SAAS;IAbtC,OAAO,CAAC,OAAO,CAAsC;IAErD,OAAO,CAAC,UAAU,CAA+B;IAEjD,OAAO,CAAC,gBAAgB,CAAS;IAEjC,0FAA0F;IAC1F,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsB;gBAE5B,SAAS,EAAE,wBAAwB;IAEhE;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAIvC;;OAEG;IACH,aAAa,IAAI,IAAI;IAUrB;;;;;OAKG;IACG,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAmBtC;;;;;OAKG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,IAAI;IA0BtC;;;;;OAKG;I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C;;OAEG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAMhC;;OAEG;IACH,qBAAqB,IAAI,OAAO;IAIhC;;;;;OAKG;IACG,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAuBzD;;;OAGG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,GAAG;QAC3F,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC;YAIa,WAAW;IA4BzB,OAAO,CAAC,gBAAgB;IASxB,OAAO,CAAC,IAAI;CAWb;AAED,eAAe,aAAa,CAAC"}
@@ -49,10 +49,10 @@ declare class ThunderIDBrowserClient<T = BrowserAuthConfig> extends ThunderIDJav
49
49
  * - Embedded mode starts an `AUTHENTICATION` flow with `ouId`, presenting the SSO session handles kept
50
50
  * from earlier flow steps. A flow that needs input fails with `interaction_required`; render the
51
51
  * sign-in for the unit instead.
52
- * - Backend mode sends `POST {ouSwitch}?ouId=` to the backend, which switches its session, then reads
53
- * the session again, so the page stays where it is. When the backend needs the user, it sends the
54
- * page to the backend's sign-in endpoint with `ouId` (unless `redirect` is `false`). The extra
55
- * parameters do not apply.
52
+ * - Backend mode sends `POST {ouSwitch}?ouId=` with `{"ouId"}` as a JSON body to the backend, which
53
+ * switches its session, then reads the session again, so the page stays where it is. When the
54
+ * backend needs the user, or answers `401`, it sends the page to the backend's sign-in endpoint
55
+ * with `ouId` (unless `redirect` is `false`). The extra parameters do not apply.
56
56
  *
57
57
  * A failed switch leaves the previous session as it was.
58
58
  *
@@ -176,18 +176,24 @@ var BackendClient = class BackendClient {
176
176
  * success the cached session is dropped, so the next read returns the unit's; on a refusal the
177
177
  * session stays as it was.
178
178
  *
179
+ * The unit goes in the query (`ouId`) and in a JSON body (`{"ouId": …}`), so a backend can read it
180
+ * from either. A `401` left after the refresh means the backend has no session to switch, so it is
181
+ * reported as `login_required` whatever its body says.
182
+ *
179
183
  * @returns The refusal, with the backend's OAuth `error` when it sent one, or `undefined` on success.
180
184
  */
181
185
  async switchOrganizationUnit(ouId) {
182
186
  const url = `${this.endpoints.ouSwitch}?${new URLSearchParams({ ouId }).toString()}`;
183
187
  const readError = async (response$1) => (await response$1.json().catch(() => ({}))).error;
184
- let response = await this.send(url, "POST");
188
+ const body = JSON.stringify({ ouId });
189
+ let response = await this.send(url, "POST", body);
185
190
  let error = response.ok ? void 0 : await readError(response);
186
191
  if (response.status === 401 && error === "session_expired") {
187
192
  if (!await this.refresh()) return { error: "login_required" };
188
- response = await this.send(url, "POST");
193
+ response = await this.send(url, "POST", body);
189
194
  error = response.ok ? void 0 : await readError(response);
190
195
  }
196
+ if (response.status === 401) error = "login_required";
191
197
  if (response.ok) {
192
198
  this.session = void 0;
193
199
  return;
@@ -279,11 +285,19 @@ var BackendClient = class BackendClient {
279
285
  if (this.wasSignedIn) queueMicrotask(() => this.markSignedOut());
280
286
  return { isSignedIn: false };
281
287
  }
282
- send(url, method) {
283
- return fetch(url, {
288
+ send(url, method, body) {
289
+ if (body === void 0) return fetch(url, {
284
290
  method,
285
291
  ...BackendClient.requestInit({ Accept: "application/json" })
286
292
  });
293
+ return fetch(url, {
294
+ body,
295
+ method,
296
+ ...BackendClient.requestInit({
297
+ Accept: "application/json",
298
+ "Content-Type": "application/json"
299
+ })
300
+ });
287
301
  }
288
302
  };
289
303
  var BackendClient_default = BackendClient;
@@ -3089,10 +3103,10 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends __thunderid_ja
3089
3103
  * - Embedded mode starts an `AUTHENTICATION` flow with `ouId`, presenting the SSO session handles kept
3090
3104
  * from earlier flow steps. A flow that needs input fails with `interaction_required`; render the
3091
3105
  * sign-in for the unit instead.
3092
- * - Backend mode sends `POST {ouSwitch}?ouId=` to the backend, which switches its session, then reads
3093
- * the session again, so the page stays where it is. When the backend needs the user, it sends the
3094
- * page to the backend's sign-in endpoint with `ouId` (unless `redirect` is `false`). The extra
3095
- * parameters do not apply.
3106
+ * - Backend mode sends `POST {ouSwitch}?ouId=` with `{"ouId"}` as a JSON body to the backend, which
3107
+ * switches its session, then reads the session again, so the page stays where it is. When the
3108
+ * backend needs the user, or answers `401`, it sends the page to the backend's sign-in endpoint
3109
+ * with `ouId` (unless `redirect` is `false`). The extra parameters do not apply.
3096
3110
  *
3097
3111
  * A failed switch leaves the previous session as it was.
3098
3112
  *