@thunderid/browser 1.9.1 → 1.9.3
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 +6 -4
- package/dist/BackendClient.d.ts.map +1 -1
- package/dist/ThunderIDBrowserClient.d.ts.map +1 -1
- package/dist/cjs/index.cjs +16 -12
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +17 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Buffer } from 'buffer/index.js';
|
|
2
2
|
if (typeof window !== 'undefined' && !window.Buffer) { window.Buffer = Buffer; }
|
|
3
|
-
import { DEFAULT_THEME, HttpClient, OIDCRequestConstants, ThunderIDAuthException, ThunderIDJavaScriptClient, ThunderIDRuntimeError, TokenConstants, arrayBufferToBase64url, base64urlToArrayBuffer, createPackageComponentLogger, extractEmojiFromUri, extractPkceStorageKeyFromState, generateFlattenedUserProfile, getTokenPermissions, getUsersMe, isEmojiUri, resolveBackendEndpoints, resolveResourceEndpoint } from "@thunderid/javascript";
|
|
3
|
+
import { DEFAULT_THEME, HttpClient, OIDCRequestConstants, ThunderIDAuthException, ThunderIDJavaScriptClient, ThunderIDRuntimeError, TokenConstants, arrayBufferToBase64url, base64urlToArrayBuffer, createPackageComponentLogger, extractEmojiFromUri, extractPkceStorageKeyFromState, generateFlattenedUserProfile, getTokenPermissions, getUsersMe, isEmojiUri, resolveBackendEndpoints, resolveRequestBaseUrl, resolveResourceEndpoint } from "@thunderid/javascript";
|
|
4
4
|
import base64url from "base64url";
|
|
5
5
|
import sha256 from "fast-sha256";
|
|
6
6
|
import { createLocalJWKSet, jwtVerify } from "jose";
|
|
@@ -178,18 +178,21 @@ var BackendClient = class BackendClient {
|
|
|
178
178
|
return (await response.json()).redirectUrl;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
181
|
-
* Maps an API URL to its backend proxy URL.
|
|
181
|
+
* Maps an API URL to its backend proxy URL. A URL already on the proxy is sent as it is, and any
|
|
182
|
+
* other path (`/users`) goes under the proxy. The backend, not the app, knows the API's address.
|
|
182
183
|
*
|
|
183
|
-
* @returns The proxy URL, or `undefined`
|
|
184
|
-
* sent with the session's credentials.
|
|
184
|
+
* @returns The proxy URL, or `undefined` for an absolute URL that isn't on the proxy and so cannot
|
|
185
|
+
* be sent with the session's credentials.
|
|
185
186
|
*/
|
|
186
187
|
toProxyUrl(url) {
|
|
187
|
-
const {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
188
|
+
const { proxy } = this.endpoints;
|
|
189
|
+
const origin = typeof window !== "undefined" ? window.location.origin : "";
|
|
190
|
+
const isPath = (value) => value.startsWith("/") && !value.startsWith("//");
|
|
191
|
+
const isUnder = (base) => url === base || url.startsWith(`${base}/`) || url.startsWith(`${base}?`);
|
|
192
|
+
const absoluteProxy = isPath(proxy) ? `${origin}${proxy}` : proxy;
|
|
193
|
+
const proxyPath = absoluteProxy.startsWith(`${origin}/`) ? absoluteProxy.slice(origin.length) : void 0;
|
|
194
|
+
if (isUnder(proxy) || isUnder(absoluteProxy) || proxyPath !== void 0 && isUnder(proxyPath)) return url;
|
|
195
|
+
return isPath(url) ? `${proxy}${url}` : void 0;
|
|
193
196
|
}
|
|
194
197
|
/**
|
|
195
198
|
* Whether a request to this URL skips the proxy and goes straight from the browser.
|
|
@@ -220,11 +223,12 @@ var BackendClient = class BackendClient {
|
|
|
220
223
|
return await response.json();
|
|
221
224
|
}
|
|
222
225
|
/**
|
|
223
|
-
* The headers and credentials mode every backend request is sent with.
|
|
226
|
+
* The headers and credentials mode every backend request is sent with. The cookies go with every
|
|
227
|
+
* request, so a backend on another origin works too when its CORS allows credentials.
|
|
224
228
|
*/
|
|
225
229
|
static requestInit(headers = {}) {
|
|
226
230
|
return {
|
|
227
|
-
credentials: "
|
|
231
|
+
credentials: "include",
|
|
228
232
|
headers: {
|
|
229
233
|
...headers,
|
|
230
234
|
[BACKEND_REQUEST_HEADER]: BACKEND_REQUEST_HEADER_VALUE
|
|
@@ -3083,7 +3087,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
3083
3087
|
await this._validateMethod();
|
|
3084
3088
|
const configData = await this.getStorageManager().getConfigData();
|
|
3085
3089
|
const profile = await getUsersMe({
|
|
3086
|
-
baseUrl: options?.baseUrl ?? configData
|
|
3090
|
+
baseUrl: options?.baseUrl ?? resolveRequestBaseUrl(configData),
|
|
3087
3091
|
fetcher: createHttpClientFetcher_default(this._browserInstanceId),
|
|
3088
3092
|
url: resolveResourceEndpoint("usersMe", configData, options?.url)
|
|
3089
3093
|
});
|