@thunderid/browser 1.9.2 → 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 +4 -3
- package/dist/BackendClient.d.ts.map +1 -1
- package/dist/cjs/index.cjs +13 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +14 -11
- 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,
|
|
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.
|
|
@@ -3084,7 +3087,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
|
|
|
3084
3087
|
await this._validateMethod();
|
|
3085
3088
|
const configData = await this.getStorageManager().getConfigData();
|
|
3086
3089
|
const profile = await getUsersMe({
|
|
3087
|
-
baseUrl: options?.baseUrl ??
|
|
3090
|
+
baseUrl: options?.baseUrl ?? resolveRequestBaseUrl(configData),
|
|
3088
3091
|
fetcher: createHttpClientFetcher_default(this._browserInstanceId),
|
|
3089
3092
|
url: resolveResourceEndpoint("usersMe", configData, options?.url)
|
|
3090
3093
|
});
|