@thunderid/browser 1.15.0 → 1.17.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/BackendClient.d.ts +14 -0
- package/dist/BackendClient.d.ts.map +1 -1
- package/dist/ThunderIDBrowserClient.d.ts +10 -1
- package/dist/ThunderIDBrowserClient.d.ts.map +1 -1
- package/dist/cjs/index.cjs +67 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +67 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/BackendClient.d.ts
CHANGED
|
@@ -68,6 +68,20 @@ declare class BackendClient {
|
|
|
68
68
|
* bounds the sign-in to that organization unit.
|
|
69
69
|
*/
|
|
70
70
|
getSignInUrl(returnTo: string, ouId?: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Switches the session to the organization unit `ouId` at the backend, without leaving the page. On
|
|
73
|
+
* success the cached session is dropped, so the next read returns the unit's; on a refusal the
|
|
74
|
+
* session stays as it was.
|
|
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
|
+
*
|
|
80
|
+
* @returns The refusal, with the backend's OAuth `error` when it sent one, or `undefined` on success.
|
|
81
|
+
*/
|
|
82
|
+
switchOrganizationUnit(ouId: string): Promise<{
|
|
83
|
+
error?: string;
|
|
84
|
+
} | undefined>;
|
|
71
85
|
/**
|
|
72
86
|
* Ends the backend session.
|
|
73
87
|
*
|
|
@@ -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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;IAIpB;;;;OAIG;IACH,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAkB3B;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrD;;;;;;;;;;OAUG;IACG,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,SAAS,CAAC;IAmCjF;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAiBhC;;;;;;OAMG;IACH,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAkB3C;;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,13 +49,22 @@ 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
|
|
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.
|
|
53
56
|
*
|
|
54
57
|
* A failed switch leaves the previous session as it was.
|
|
55
58
|
*
|
|
56
59
|
* @throws {ThunderIDAPIError} With a code from `OrganizationUnitSwitchErrorCodes`.
|
|
57
60
|
*/
|
|
58
61
|
switchOrganizationUnit(organizationUnitId: string, options?: SwitchOrganizationUnitOptions): Promise<User | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* Backend mode: asks the backend's `ouSwitch` endpoint to switch, then reads its session again, so the
|
|
64
|
+
* page stays where it is. When the backend needs the user, the page goes to the backend's sign-in for
|
|
65
|
+
* the unit instead, unless `redirect` is off.
|
|
66
|
+
*/
|
|
67
|
+
private _switchOrganizationUnitOnBackend;
|
|
59
68
|
/**
|
|
60
69
|
* Switches back-channel by exchanging the session's device secret at the unit's token endpoint.
|
|
61
70
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThunderIDBrowserClient.d.ts","sourceRoot":"","sources":["../src/ThunderIDBrowserClient.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EAEzB,IAAI,EACJ,gBAAgB,EAChB,OAAO,EACP,aAAa,EAGb,OAAO,EACP,aAAa,EAGb,iBAAiB,EACjB,YAAY,EACZ,WAAW,EAoBX,6BAA6B,EAG9B,MAAM,uBAAuB,CAAC;AAK/B,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AAEzD,OAAO,YAAY,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,sBAAsB,EAAC,MAAM,8BAA8B,CAAC;AAsDpE,cAAM,sBAAsB,CAAC,CAAC,GAAG,iBAAiB,CAAE,SAAQ,yBAAyB,CAAC,CAA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;IASjD,kBAAkB,IAAI,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IASzC,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI5F;;;;;;;;OAQG;IACU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiD7G,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,SAAS;IAMjB,OAAO,CAAC,cAAc,CAEpB;IAEF,OAAO,CAAC,eAAe,CAErB;IAEF,OAAO,CAAC,sCAAsC;YAMhC,yBAAyB;IA8BvB,aAAa,IAAI,MAAM;WAInB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlD;AAED,eAAe,sBAAsB,CAAC"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -172,6 +172,36 @@ var BackendClient = class BackendClient {
|
|
|
172
172
|
}).toString()}`;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
|
+
* Switches the session to the organization unit `ouId` at the backend, without leaving the page. On
|
|
176
|
+
* success the cached session is dropped, so the next read returns the unit's; on a refusal the
|
|
177
|
+
* session stays as it was.
|
|
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
|
+
*
|
|
183
|
+
* @returns The refusal, with the backend's OAuth `error` when it sent one, or `undefined` on success.
|
|
184
|
+
*/
|
|
185
|
+
async switchOrganizationUnit(ouId) {
|
|
186
|
+
const url = `${this.endpoints.ouSwitch}?${new URLSearchParams({ ouId }).toString()}`;
|
|
187
|
+
const readError = async (response$1) => (await response$1.json().catch(() => ({}))).error;
|
|
188
|
+
const body = JSON.stringify({ ouId });
|
|
189
|
+
let response = await this.send(url, "POST", body);
|
|
190
|
+
let error = response.ok ? void 0 : await readError(response);
|
|
191
|
+
if (response.status === 401 && error === "session_expired") {
|
|
192
|
+
if (!await this.refresh()) return { error: "login_required" };
|
|
193
|
+
response = await this.send(url, "POST", body);
|
|
194
|
+
error = response.ok ? void 0 : await readError(response);
|
|
195
|
+
}
|
|
196
|
+
if (response.status === 401) error = "login_required";
|
|
197
|
+
if (response.ok) {
|
|
198
|
+
this.session = void 0;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (error === "login_required") this.markSignedOut();
|
|
202
|
+
return error ? { error } : {};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
175
205
|
* Ends the backend session.
|
|
176
206
|
*
|
|
177
207
|
* @returns The URL the browser visits to end the session at the authorization server.
|
|
@@ -255,11 +285,19 @@ var BackendClient = class BackendClient {
|
|
|
255
285
|
if (this.wasSignedIn) queueMicrotask(() => this.markSignedOut());
|
|
256
286
|
return { isSignedIn: false };
|
|
257
287
|
}
|
|
258
|
-
send(url, method) {
|
|
259
|
-
return fetch(url, {
|
|
288
|
+
send(url, method, body) {
|
|
289
|
+
if (body === void 0) return fetch(url, {
|
|
260
290
|
method,
|
|
261
291
|
...BackendClient.requestInit({ Accept: "application/json" })
|
|
262
292
|
});
|
|
293
|
+
return fetch(url, {
|
|
294
|
+
body,
|
|
295
|
+
method,
|
|
296
|
+
...BackendClient.requestInit({
|
|
297
|
+
Accept: "application/json",
|
|
298
|
+
"Content-Type": "application/json"
|
|
299
|
+
})
|
|
300
|
+
});
|
|
263
301
|
}
|
|
264
302
|
};
|
|
265
303
|
var BackendClient_default = BackendClient;
|
|
@@ -3065,7 +3103,10 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends __thunderid_ja
|
|
|
3065
3103
|
* - Embedded mode starts an `AUTHENTICATION` flow with `ouId`, presenting the SSO session handles kept
|
|
3066
3104
|
* from earlier flow steps. A flow that needs input fails with `interaction_required`; render the
|
|
3067
3105
|
* sign-in for the unit instead.
|
|
3068
|
-
* - Backend mode sends
|
|
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.
|
|
3069
3110
|
*
|
|
3070
3111
|
* A failed switch leaves the previous session as it was.
|
|
3071
3112
|
*
|
|
@@ -3074,11 +3115,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends __thunderid_ja
|
|
|
3074
3115
|
async switchOrganizationUnit(organizationUnitId, options = {}) {
|
|
3075
3116
|
await this.isInitialized();
|
|
3076
3117
|
if (typeof organizationUnitId !== "string" || organizationUnitId.trim() === "") throw new __thunderid_javascript.ThunderIDAPIError("An organization unit identifier is required.", __thunderid_javascript.OrganizationUnitSwitchErrorCodes.InvalidOrganizationUnit, "browser", 400);
|
|
3077
|
-
if (this._backend)
|
|
3078
|
-
location.href = this._backend.getSignInUrl(`${window.location.pathname}${window.location.search}`, organizationUnitId);
|
|
3079
|
-
await SPAUtils_default.waitTillPageRedirect();
|
|
3080
|
-
return;
|
|
3081
|
-
}
|
|
3118
|
+
if (this._backend) return this._switchOrganizationUnitOnBackend(organizationUnitId, options.redirect !== false);
|
|
3082
3119
|
const { redirect = true,...params } = options;
|
|
3083
3120
|
const sm = this.getStorageManager();
|
|
3084
3121
|
const config = await sm.getConfigData();
|
|
@@ -3112,6 +3149,28 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends __thunderid_ja
|
|
|
3112
3149
|
await SPAUtils_default.waitTillPageRedirect();
|
|
3113
3150
|
}
|
|
3114
3151
|
/**
|
|
3152
|
+
* Backend mode: asks the backend's `ouSwitch` endpoint to switch, then reads its session again, so the
|
|
3153
|
+
* page stays where it is. When the backend needs the user, the page goes to the backend's sign-in for
|
|
3154
|
+
* the unit instead, unless `redirect` is off.
|
|
3155
|
+
*/
|
|
3156
|
+
async _switchOrganizationUnitOnBackend(organizationUnitId, redirect) {
|
|
3157
|
+
let refusal;
|
|
3158
|
+
try {
|
|
3159
|
+
refusal = await this._backend.switchOrganizationUnit(organizationUnitId);
|
|
3160
|
+
} catch (error) {
|
|
3161
|
+
throw ThunderIDBrowserClient._toSwitchError(void 0, error);
|
|
3162
|
+
}
|
|
3163
|
+
if (refusal) {
|
|
3164
|
+
if (!redirect || !refusal.error || !INTERACTION_ERRORS.includes(refusal.error)) throw ThunderIDBrowserClient._toSwitchError(refusal.error);
|
|
3165
|
+
location.href = this._backend.getSignInUrl(`${window.location.pathname}${window.location.search}`, organizationUnitId);
|
|
3166
|
+
await SPAUtils_default.waitTillPageRedirect();
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
const user = await this.getUser();
|
|
3170
|
+
this._emitHook(Hooks_default.SignIn, user);
|
|
3171
|
+
return user;
|
|
3172
|
+
}
|
|
3173
|
+
/**
|
|
3115
3174
|
* Switches back-channel by exchanging the session's device secret at the unit's token endpoint.
|
|
3116
3175
|
*
|
|
3117
3176
|
* @returns The user, `false` when the server needs the user, or `undefined` when the session holds no
|