@logto/browser 0.1.17 → 0.2.1
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 +0 -1
- package/lib/errors.js +0 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.js +4 -10
- package/package.json +3 -3
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,14 +1,15 @@
|
|
|
1
|
-
import { IdTokenClaims,
|
|
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,
|
|
5
|
-
export { LogtoError, OidcError } from '@logto/js';
|
|
4
|
+
export type { IdTokenClaims, LogtoErrorCode } from '@logto/js';
|
|
5
|
+
export { LogtoError, OidcError, Prompt } from '@logto/js';
|
|
6
6
|
export * from './errors';
|
|
7
7
|
export declare type LogtoConfig = {
|
|
8
8
|
endpoint: string;
|
|
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
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.LogtoSignInSessionItemSchema = exports.OidcError = exports.LogtoError = void 0;
|
|
16
|
+
exports.LogtoSignInSessionItemSchema = exports.Prompt = exports.OidcError = exports.LogtoError = void 0;
|
|
17
17
|
const js_1 = require("@logto/js");
|
|
18
18
|
const jose_1 = require("jose");
|
|
19
19
|
const lodash_once_1 = __importDefault(require("lodash.once"));
|
|
@@ -23,6 +23,7 @@ const utils_1 = require("./utils");
|
|
|
23
23
|
var js_2 = require("@logto/js");
|
|
24
24
|
Object.defineProperty(exports, "LogtoError", { enumerable: true, get: function () { return js_2.LogtoError; } });
|
|
25
25
|
Object.defineProperty(exports, "OidcError", { enumerable: true, get: function () { return js_2.OidcError; } });
|
|
26
|
+
Object.defineProperty(exports, "Prompt", { enumerable: true, get: function () { return js_2.Prompt; } });
|
|
26
27
|
__exportStar(require("./errors"), exports);
|
|
27
28
|
exports.LogtoSignInSessionItemSchema = (0, superstruct_1.type)({
|
|
28
29
|
redirectUri: (0, superstruct_1.string)(),
|
|
@@ -37,6 +38,7 @@ class LogtoClient {
|
|
|
37
38
|
this.getAccessTokenPromiseMap = new Map();
|
|
38
39
|
this.logtoConfig = {
|
|
39
40
|
...logtoConfig,
|
|
41
|
+
prompt: logtoConfig.prompt ?? js_1.Prompt.Consent,
|
|
40
42
|
scopes: (0, js_1.withReservedScopes)(logtoConfig.scopes).split(' '),
|
|
41
43
|
};
|
|
42
44
|
this.logtoStorageKey = (0, utils_1.buildLogtoKey)(logtoConfig.appId);
|
|
@@ -130,14 +132,6 @@ class LogtoClient {
|
|
|
130
132
|
}
|
|
131
133
|
return (0, js_1.decodeIdToken)(this.idToken);
|
|
132
134
|
}
|
|
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
135
|
async signIn(redirectUri) {
|
|
142
136
|
const { appId: clientId, resources, scopes } = this.logtoConfig;
|
|
143
137
|
const { authorizationEndpoint } = await this.getOidcConfig();
|
|
@@ -263,7 +257,7 @@ class LogtoClient {
|
|
|
263
257
|
}
|
|
264
258
|
}
|
|
265
259
|
saveCodeToken({ refreshToken, idToken, scope, accessToken, expiresIn, }) {
|
|
266
|
-
this.refreshToken = refreshToken;
|
|
260
|
+
this.refreshToken = refreshToken ?? null;
|
|
267
261
|
this.idToken = idToken;
|
|
268
262
|
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
269
263
|
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
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"exports": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"prepack": "pnpm test"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@logto/js": "^0.
|
|
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",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "b572a2f02cec128f24efc6a030ea68c7e44e9384"
|
|
58
58
|
}
|