@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.
package/dist/index.js CHANGED
@@ -174,18 +174,24 @@ var BackendClient = class BackendClient {
174
174
  * success the cached session is dropped, so the next read returns the unit's; on a refusal the
175
175
  * session stays as it was.
176
176
  *
177
+ * The unit goes in the query (`ouId`) and in a JSON body (`{"ouId": …}`), so a backend can read it
178
+ * from either. A `401` left after the refresh means the backend has no session to switch, so it is
179
+ * reported as `login_required` whatever its body says.
180
+ *
177
181
  * @returns The refusal, with the backend's OAuth `error` when it sent one, or `undefined` on success.
178
182
  */
179
183
  async switchOrganizationUnit(ouId) {
180
184
  const url = `${this.endpoints.ouSwitch}?${new URLSearchParams({ ouId }).toString()}`;
181
185
  const readError = async (response$1) => (await response$1.json().catch(() => ({}))).error;
182
- let response = await this.send(url, "POST");
186
+ const body = JSON.stringify({ ouId });
187
+ let response = await this.send(url, "POST", body);
183
188
  let error = response.ok ? void 0 : await readError(response);
184
189
  if (response.status === 401 && error === "session_expired") {
185
190
  if (!await this.refresh()) return { error: "login_required" };
186
- response = await this.send(url, "POST");
191
+ response = await this.send(url, "POST", body);
187
192
  error = response.ok ? void 0 : await readError(response);
188
193
  }
194
+ if (response.status === 401) error = "login_required";
189
195
  if (response.ok) {
190
196
  this.session = void 0;
191
197
  return;
@@ -277,11 +283,19 @@ var BackendClient = class BackendClient {
277
283
  if (this.wasSignedIn) queueMicrotask(() => this.markSignedOut());
278
284
  return { isSignedIn: false };
279
285
  }
280
- send(url, method) {
281
- return fetch(url, {
286
+ send(url, method, body) {
287
+ if (body === void 0) return fetch(url, {
282
288
  method,
283
289
  ...BackendClient.requestInit({ Accept: "application/json" })
284
290
  });
291
+ return fetch(url, {
292
+ body,
293
+ method,
294
+ ...BackendClient.requestInit({
295
+ Accept: "application/json",
296
+ "Content-Type": "application/json"
297
+ })
298
+ });
285
299
  }
286
300
  };
287
301
  var BackendClient_default = BackendClient;
@@ -3087,10 +3101,10 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
3087
3101
  * - Embedded mode starts an `AUTHENTICATION` flow with `ouId`, presenting the SSO session handles kept
3088
3102
  * from earlier flow steps. A flow that needs input fails with `interaction_required`; render the
3089
3103
  * sign-in for the unit instead.
3090
- * - Backend mode sends `POST {ouSwitch}?ouId=` to the backend, which switches its session, then reads
3091
- * the session again, so the page stays where it is. When the backend needs the user, it sends the
3092
- * page to the backend's sign-in endpoint with `ouId` (unless `redirect` is `false`). The extra
3093
- * parameters do not apply.
3104
+ * - Backend mode sends `POST {ouSwitch}?ouId=` with `{"ouId"}` as a JSON body to the backend, which
3105
+ * switches its session, then reads the session again, so the page stays where it is. When the
3106
+ * backend needs the user, or answers `401`, it sends the page to the backend's sign-in endpoint
3107
+ * with `ouId` (unless `redirect` is `false`). The extra parameters do not apply.
3094
3108
  *
3095
3109
  * A failed switch leaves the previous session as it was.
3096
3110
  *