@thunderid/browser 1.9.0 → 1.9.2

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
@@ -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, 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, resolveApiBaseUrl, resolveBackendEndpoints, resolveResourceEndpoint } from "@thunderid/javascript";
4
4
  import base64url from "base64url";
5
5
  import sha256 from "fast-sha256";
6
6
  import { createLocalJWKSet, jwtVerify } from "jose";
@@ -220,11 +220,12 @@ var BackendClient = class BackendClient {
220
220
  return await response.json();
221
221
  }
222
222
  /**
223
- * The headers and credentials mode every backend request is sent with.
223
+ * The headers and credentials mode every backend request is sent with. The cookies go with every
224
+ * request, so a backend on another origin works too when its CORS allows credentials.
224
225
  */
225
226
  static requestInit(headers = {}) {
226
227
  return {
227
- credentials: "same-origin",
228
+ credentials: "include",
228
229
  headers: {
229
230
  ...headers,
230
231
  [BACKEND_REQUEST_HEADER]: BACKEND_REQUEST_HEADER_VALUE
@@ -3083,7 +3084,7 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
3083
3084
  await this._validateMethod();
3084
3085
  const configData = await this.getStorageManager().getConfigData();
3085
3086
  const profile = await getUsersMe({
3086
- baseUrl: options?.baseUrl ?? configData?.baseUrl,
3087
+ baseUrl: options?.baseUrl ?? resolveApiBaseUrl(configData),
3087
3088
  fetcher: createHttpClientFetcher_default(this._browserInstanceId),
3088
3089
  url: resolveResourceEndpoint("usersMe", configData, options?.url)
3089
3090
  });
@@ -3097,6 +3098,23 @@ var ThunderIDBrowserClient = class ThunderIDBrowserClient extends ThunderIDJavaS
3097
3098
  return super.getAccessToken(sessionId);
3098
3099
  }
3099
3100
  /**
3101
+ * The permissions the signed-in user's access token grants, for example to hide a page the user
3102
+ * cannot use. The server still checks every request.
3103
+ *
3104
+ * In backend mode they come only from the backend's session (`scope`): the token stays on the backend,
3105
+ * so a session without `scope` grants nothing. Otherwise they are read from the access token's `scope`
3106
+ * or `scopes` claim.
3107
+ *
3108
+ * @returns The granted permissions, or an empty list when none can be read.
3109
+ */
3110
+ async getGrantedPermissions() {
3111
+ if (this._backend) {
3112
+ const { scope } = await this._backend.getSession();
3113
+ return typeof scope === "string" ? scope.split(" ").filter((entry) => entry.length > 0) : [];
3114
+ }
3115
+ return getTokenPermissions(await this.getAccessToken());
3116
+ }
3117
+ /**
3100
3118
  * The access token for requests under `endpoints.backend.bypass`. Like a client credentials token it
3101
3119
  * has no refresh token: it is kept in the session storage until it nears expiry, then requested again.
3102
3120
  *