@logto/browser 0.1.16 → 0.2.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/lib/errors.d.ts CHANGED
@@ -6,7 +6,6 @@ declare const logtoClientErrorCodes: Readonly<{
6
6
  };
7
7
  not_authenticated: string;
8
8
  get_access_token_by_refresh_token_failed: string;
9
- fetch_user_info_failed: string;
10
9
  invalid_id_token: string;
11
10
  }>;
12
11
  export declare type LogtoClientErrorCode = NormalizeKeyPaths<typeof logtoClientErrorCodes>;
package/lib/errors.js CHANGED
@@ -12,7 +12,6 @@ const logtoClientErrorCodes = Object.freeze({
12
12
  },
13
13
  not_authenticated: 'Not authenticated.',
14
14
  get_access_token_by_refresh_token_failed: 'Failed to get access token by refresh token.',
15
- fetch_user_info_failed: 'Unable to fetch user info. The access token may be invalid.',
16
15
  invalid_id_token: 'Invalid id token.',
17
16
  });
18
17
  const getMessageByErrorCode = (errorCode) => {
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { IdTokenClaims, Requester, UserInfoResponse } from '@logto/js';
1
+ import { IdTokenClaims, Prompt, Requester } from '@logto/js';
2
2
  import { Nullable } from '@silverhand/essentials';
3
3
  import { Infer } from 'superstruct';
4
- export type { IdTokenClaims, UserInfoResponse, LogtoErrorCode } from '@logto/js';
4
+ export type { IdTokenClaims, LogtoErrorCode } from '@logto/js';
5
5
  export { LogtoError, OidcError } from '@logto/js';
6
6
  export * from './errors';
7
7
  export declare type LogtoConfig = {
@@ -9,6 +9,7 @@ export declare type LogtoConfig = {
9
9
  appId: string;
10
10
  scopes?: string[];
11
11
  resources?: string[];
12
+ prompt?: Prompt;
12
13
  usingPersistStorage?: boolean;
13
14
  };
14
15
  export declare type AccessToken = {
@@ -31,7 +32,6 @@ export default class LogtoClient {
31
32
  protected readonly getOidcConfig: () => Promise<import("@silverhand/essentials").KeysToCamelCase<{
32
33
  authorization_endpoint: string;
33
34
  token_endpoint: string;
34
- userinfo_endpoint: string;
35
35
  end_session_endpoint: string;
36
36
  revocation_endpoint: string;
37
37
  jwks_uri: string;
@@ -53,7 +53,6 @@ export default class LogtoClient {
53
53
  private set idToken(value);
54
54
  getAccessToken(resource?: string): Promise<string>;
55
55
  getIdTokenClaims(): IdTokenClaims;
56
- fetchUserInfo(): Promise<UserInfoResponse>;
57
56
  signIn(redirectUri: string): Promise<void>;
58
57
  isSignInRedirected(url: string): boolean;
59
58
  handleSignInCallback(callbackUri: string): Promise<void>;
package/lib/index.js CHANGED
@@ -37,6 +37,7 @@ class LogtoClient {
37
37
  this.getAccessTokenPromiseMap = new Map();
38
38
  this.logtoConfig = {
39
39
  ...logtoConfig,
40
+ prompt: logtoConfig.prompt ?? js_1.Prompt.Consent,
40
41
  scopes: (0, js_1.withReservedScopes)(logtoConfig.scopes).split(' '),
41
42
  };
42
43
  this.logtoStorageKey = (0, utils_1.buildLogtoKey)(logtoConfig.appId);
@@ -130,14 +131,6 @@ class LogtoClient {
130
131
  }
131
132
  return (0, js_1.decodeIdToken)(this.idToken);
132
133
  }
133
- async fetchUserInfo() {
134
- const { userinfoEndpoint } = await this.getOidcConfig();
135
- const accessToken = await this.getAccessToken();
136
- if (!accessToken) {
137
- throw new errors_1.LogtoClientError('fetch_user_info_failed');
138
- }
139
- return (0, js_1.fetchUserInfo)(userinfoEndpoint, accessToken, this.requester);
140
- }
141
134
  async signIn(redirectUri) {
142
135
  const { appId: clientId, resources, scopes } = this.logtoConfig;
143
136
  const { authorizationEndpoint } = await this.getOidcConfig();
@@ -219,7 +212,13 @@ class LogtoClient {
219
212
  const accessTokenKey = (0, utils_1.buildAccessTokenKey)(resource);
220
213
  const { appId: clientId } = this.logtoConfig;
221
214
  const { tokenEndpoint } = await this.getOidcConfig();
222
- const { accessToken, refreshToken, idToken, scope, expiresIn } = await (0, js_1.fetchTokenByRefreshToken)({ clientId, tokenEndpoint, refreshToken: this.refreshToken, resource }, this.requester);
215
+ const { accessToken, refreshToken, idToken, scope, expiresIn } = await (0, js_1.fetchTokenByRefreshToken)({
216
+ clientId,
217
+ tokenEndpoint,
218
+ refreshToken: this.refreshToken,
219
+ resource,
220
+ scopes: resource ? ['offline_access'] : undefined, // Force remove openid scope from the request
221
+ }, this.requester);
223
222
  this.accessTokenMap.set(accessTokenKey, {
224
223
  token: accessToken,
225
224
  scope,
@@ -257,7 +256,7 @@ class LogtoClient {
257
256
  }
258
257
  }
259
258
  saveCodeToken({ refreshToken, idToken, scope, accessToken, expiresIn, }) {
260
- this.refreshToken = refreshToken;
259
+ this.refreshToken = refreshToken ?? null;
261
260
  this.idToken = idToken;
262
261
  // NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
263
262
  const accessTokenKey = (0, utils_1.buildAccessTokenKey)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/browser",
3
- "version": "0.1.16",
3
+ "version": "0.2.0",
4
4
  "main": "./lib/index.js",
5
5
  "exports": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
@@ -23,12 +23,12 @@
23
23
  "prepack": "pnpm test"
24
24
  },
25
25
  "dependencies": {
26
- "@logto/js": "^0.1.16",
26
+ "@logto/js": "^0.2.0",
27
27
  "@silverhand/essentials": "^1.1.6",
28
28
  "jose": "^4.5.0",
29
29
  "lodash.get": "^4.4.2",
30
30
  "lodash.once": "^4.1.1",
31
- "superstruct": "^0.15.3"
31
+ "superstruct": "^0.16.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@jest/types": "^27.5.1",
@@ -54,5 +54,5 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  },
57
- "gitHead": "b56e794cea7ba791c73cd2da6e4ea405223d6970"
57
+ "gitHead": "5166ae926de86816f29229f18bc756f3b17fb57b"
58
58
  }