@logto/client 2.6.5 → 2.6.7
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/adapter/defaults.cjs +1 -3
- package/lib/adapter/defaults.js +1 -3
- package/lib/client.cjs +9 -4
- package/lib/client.d.ts +4 -0
- package/lib/client.js +9 -4
- package/lib/mock.d.ts +16 -30
- package/lib/utils/memoize.cjs +1 -1
- package/lib/utils/memoize.js +1 -1
- package/package.json +11 -15
package/lib/adapter/defaults.cjs
CHANGED
|
@@ -17,9 +17,7 @@ class DefaultJwtVerifier {
|
|
|
17
17
|
async verifyIdToken(idToken) {
|
|
18
18
|
const { appId } = this.client.logtoConfig;
|
|
19
19
|
const { issuer, jwksUri } = await this.client.getOidcConfig();
|
|
20
|
-
|
|
21
|
-
this.getJwtVerifyGetKey = jose.createRemoteJWKSet(new URL(jwksUri));
|
|
22
|
-
}
|
|
20
|
+
this.getJwtVerifyGetKey ||= jose.createRemoteJWKSet(new URL(jwksUri));
|
|
23
21
|
await verifyIdToken(idToken, appId, issuer, this.getJwtVerifyGetKey);
|
|
24
22
|
}
|
|
25
23
|
}
|
package/lib/adapter/defaults.js
CHANGED
|
@@ -15,9 +15,7 @@ class DefaultJwtVerifier {
|
|
|
15
15
|
async verifyIdToken(idToken) {
|
|
16
16
|
const { appId } = this.client.logtoConfig;
|
|
17
17
|
const { issuer, jwksUri } = await this.client.getOidcConfig();
|
|
18
|
-
|
|
19
|
-
this.getJwtVerifyGetKey = createRemoteJWKSet(new URL(jwksUri));
|
|
20
|
-
}
|
|
18
|
+
this.getJwtVerifyGetKey ||= createRemoteJWKSet(new URL(jwksUri));
|
|
21
19
|
await verifyIdToken(idToken, appId, issuer, this.getJwtVerifyGetKey);
|
|
22
20
|
}
|
|
23
21
|
}
|
package/lib/client.cjs
CHANGED
|
@@ -61,6 +61,10 @@ class StandardLogtoClient {
|
|
|
61
61
|
* Clear the access token from the cache storage.
|
|
62
62
|
*/
|
|
63
63
|
this.clearAccessToken = memoize.memoize(this.#clearAccessToken);
|
|
64
|
+
/**
|
|
65
|
+
* Clear all cached tokens from storage.
|
|
66
|
+
*/
|
|
67
|
+
this.clearAllTokens = memoize.memoize(this.#clearAllTokens);
|
|
64
68
|
/**
|
|
65
69
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
66
70
|
* callback URI and exchanging it for the tokens.
|
|
@@ -183,9 +187,7 @@ class StandardLogtoClient {
|
|
|
183
187
|
});
|
|
184
188
|
await Promise.all([
|
|
185
189
|
this.setSignInSession({ redirectUri, postRedirectUri, codeVerifier, state }),
|
|
186
|
-
this.
|
|
187
|
-
this.setIdToken(null),
|
|
188
|
-
this.clearAccessToken(),
|
|
190
|
+
this.clearAllTokens(),
|
|
189
191
|
]);
|
|
190
192
|
await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
|
|
191
193
|
}
|
|
@@ -233,7 +235,7 @@ class StandardLogtoClient {
|
|
|
233
235
|
postLogoutRedirectUri,
|
|
234
236
|
clientId,
|
|
235
237
|
});
|
|
236
|
-
await
|
|
238
|
+
await this.clearAllTokens();
|
|
237
239
|
await this.adapter.navigate(url, { redirectUri: postLogoutRedirectUri, for: 'sign-out' });
|
|
238
240
|
}
|
|
239
241
|
async getSignInSession() {
|
|
@@ -351,6 +353,9 @@ class StandardLogtoClient {
|
|
|
351
353
|
this.accessTokenMap.clear();
|
|
352
354
|
await this.adapter.storage.removeItem('accessToken');
|
|
353
355
|
}
|
|
356
|
+
async #clearAllTokens() {
|
|
357
|
+
await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
|
|
358
|
+
}
|
|
354
359
|
async #handleSignInCallback(callbackUri) {
|
|
355
360
|
const signInSession = await this.getSignInSession();
|
|
356
361
|
if (!signInSession) {
|
package/lib/client.d.ts
CHANGED
|
@@ -70,6 +70,10 @@ export declare class StandardLogtoClient {
|
|
|
70
70
|
* Clear the access token from the cache storage.
|
|
71
71
|
*/
|
|
72
72
|
readonly clearAccessToken: (this: unknown) => Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Clear all cached tokens from storage.
|
|
75
|
+
*/
|
|
76
|
+
readonly clearAllTokens: (this: unknown) => Promise<void>;
|
|
73
77
|
/**
|
|
74
78
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
75
79
|
* callback URI and exchanging it for the tokens.
|
package/lib/client.js
CHANGED
|
@@ -59,6 +59,10 @@ class StandardLogtoClient {
|
|
|
59
59
|
* Clear the access token from the cache storage.
|
|
60
60
|
*/
|
|
61
61
|
this.clearAccessToken = memoize(this.#clearAccessToken);
|
|
62
|
+
/**
|
|
63
|
+
* Clear all cached tokens from storage.
|
|
64
|
+
*/
|
|
65
|
+
this.clearAllTokens = memoize(this.#clearAllTokens);
|
|
62
66
|
/**
|
|
63
67
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
64
68
|
* callback URI and exchanging it for the tokens.
|
|
@@ -181,9 +185,7 @@ class StandardLogtoClient {
|
|
|
181
185
|
});
|
|
182
186
|
await Promise.all([
|
|
183
187
|
this.setSignInSession({ redirectUri, postRedirectUri, codeVerifier, state }),
|
|
184
|
-
this.
|
|
185
|
-
this.setIdToken(null),
|
|
186
|
-
this.clearAccessToken(),
|
|
188
|
+
this.clearAllTokens(),
|
|
187
189
|
]);
|
|
188
190
|
await this.adapter.navigate(signInUri, { redirectUri, for: 'sign-in' });
|
|
189
191
|
}
|
|
@@ -231,7 +233,7 @@ class StandardLogtoClient {
|
|
|
231
233
|
postLogoutRedirectUri,
|
|
232
234
|
clientId,
|
|
233
235
|
});
|
|
234
|
-
await
|
|
236
|
+
await this.clearAllTokens();
|
|
235
237
|
await this.adapter.navigate(url, { redirectUri: postLogoutRedirectUri, for: 'sign-out' });
|
|
236
238
|
}
|
|
237
239
|
async getSignInSession() {
|
|
@@ -349,6 +351,9 @@ class StandardLogtoClient {
|
|
|
349
351
|
this.accessTokenMap.clear();
|
|
350
352
|
await this.adapter.storage.removeItem('accessToken');
|
|
351
353
|
}
|
|
354
|
+
async #clearAllTokens() {
|
|
355
|
+
await Promise.all([this.setRefreshToken(null), this.setIdToken(null), this.clearAccessToken()]);
|
|
356
|
+
}
|
|
352
357
|
async #handleSignInCallback(callbackUri) {
|
|
353
358
|
const signInSession = await this.getSignInSession();
|
|
354
359
|
if (!signInSession) {
|
package/lib/mock.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
1
|
import { type OidcConfigResponse, Prompt } from '@logto/js';
|
|
3
2
|
import { type Nullable } from '@silverhand/essentials';
|
|
3
|
+
import nock from 'nock';
|
|
4
|
+
import { type Mock } from 'vitest';
|
|
4
5
|
import type { Storage } from './adapter/index.js';
|
|
5
6
|
import type { AccessToken, LogtoConfig, LogtoSignInSessionItem } from './index.js';
|
|
6
7
|
import LogtoClient from './index.js';
|
|
@@ -35,38 +36,22 @@ export declare const accessToken = "access_token_value";
|
|
|
35
36
|
export declare const refreshToken = "new_refresh_token_value";
|
|
36
37
|
export declare const idToken = "id_token_value";
|
|
37
38
|
export declare const currentUnixTimeStamp: number;
|
|
38
|
-
export declare const mockFetchOidcConfig: (delay?: number) =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}>, [], any>;
|
|
47
|
-
export declare const fetchOidcConfig: jest.Mock<Promise<{
|
|
48
|
-
authorizationEndpoint: string;
|
|
49
|
-
tokenEndpoint: string;
|
|
50
|
-
userinfoEndpoint: string;
|
|
51
|
-
endSessionEndpoint: string;
|
|
52
|
-
revocationEndpoint: string;
|
|
53
|
-
jwksUri: string;
|
|
54
|
-
issuer: string;
|
|
55
|
-
}>, [], any>;
|
|
56
|
-
export declare const requester: jest.Mock<any, any, any>;
|
|
57
|
-
export declare const failingRequester: jest.Mock<any, any, any>;
|
|
58
|
-
export declare const navigate: jest.Mock<any, any, any>;
|
|
59
|
-
export declare const generateCodeChallenge: jest.Mock<Promise<string>, [], any>;
|
|
60
|
-
export declare const generateCodeVerifier: jest.Mock<string, [], any>;
|
|
61
|
-
export declare const generateState: jest.Mock<string, [], any>;
|
|
39
|
+
export declare const mockFetchOidcConfig: (delay?: number) => Mock<unknown[], Promise<OidcConfigResponse>>;
|
|
40
|
+
export declare const fetchOidcConfig: Mock<unknown[], Promise<OidcConfigResponse>>;
|
|
41
|
+
export declare const requester: Mock<any, any>;
|
|
42
|
+
export declare const failingRequester: Mock<any, any>;
|
|
43
|
+
export declare const navigate: Mock<any, any>;
|
|
44
|
+
export declare const generateCodeChallenge: Mock<[], Promise<string>>;
|
|
45
|
+
export declare const generateCodeVerifier: Mock<[], string>;
|
|
46
|
+
export declare const generateState: Mock<[], string>;
|
|
62
47
|
export declare const createAdapters: (withCache?: boolean) => {
|
|
63
|
-
requester:
|
|
48
|
+
requester: Mock<any, any>;
|
|
64
49
|
storage: MockedStorage;
|
|
65
50
|
unstable_cache: import("@silverhand/essentials").Optional<MockedStorage>;
|
|
66
|
-
navigate:
|
|
67
|
-
generateCodeChallenge:
|
|
68
|
-
generateCodeVerifier:
|
|
69
|
-
generateState:
|
|
51
|
+
navigate: Mock<any, any>;
|
|
52
|
+
generateCodeChallenge: Mock<[], Promise<string>>;
|
|
53
|
+
generateCodeVerifier: Mock<[], string>;
|
|
54
|
+
generateState: Mock<[], string>;
|
|
70
55
|
};
|
|
71
56
|
export declare const createClient: (prompt?: Prompt, storage?: MockedStorage, withCache?: boolean, scopes?: string[]) => LogtoClientWithAccessors;
|
|
72
57
|
/**
|
|
@@ -79,3 +64,4 @@ export declare class LogtoClientWithAccessors extends LogtoClient {
|
|
|
79
64
|
setSignInSessionItem(item: Nullable<LogtoSignInSessionItem>): Promise<void>;
|
|
80
65
|
getAccessTokenMap(): Map<string, AccessToken>;
|
|
81
66
|
}
|
|
67
|
+
export declare const nocked: nock.Scope;
|
package/lib/utils/memoize.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
function memoize(run) {
|
|
4
4
|
const promiseCache = new Map();
|
|
5
5
|
const memoized = async function (...args) {
|
|
6
|
-
const promiseKey = args
|
|
6
|
+
const promiseKey = JSON.stringify(args);
|
|
7
7
|
const cachedPromise = promiseCache.get(promiseKey);
|
|
8
8
|
if (cachedPromise) {
|
|
9
9
|
return cachedPromise;
|
package/lib/utils/memoize.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function memoize(run) {
|
|
2
2
|
const promiseCache = new Map();
|
|
3
3
|
const memoized = async function (...args) {
|
|
4
|
-
const promiseKey = args
|
|
4
|
+
const promiseKey = JSON.stringify(args);
|
|
5
5
|
const cachedPromise = promiseCache.get(promiseKey);
|
|
6
6
|
if (cachedPromise) {
|
|
7
7
|
return cachedPromise;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/client",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -35,22 +35,17 @@
|
|
|
35
35
|
"@logto/js": "^4.1.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@silverhand/
|
|
40
|
-
"@silverhand/ts-config": "^5.0.0",
|
|
41
|
-
"@swc/core": "^1.3.50",
|
|
42
|
-
"@swc/jest": "^0.2.24",
|
|
43
|
-
"@types/jest": "^29.5.0",
|
|
38
|
+
"@silverhand/eslint-config": "^6.0.1",
|
|
39
|
+
"@silverhand/ts-config": "^6.0.0",
|
|
44
40
|
"@types/node": "^20.11.19",
|
|
41
|
+
"@vitest/coverage-v8": "^1.4.0",
|
|
45
42
|
"eslint": "^8.57.0",
|
|
46
|
-
"
|
|
47
|
-
"jest-matcher-specific-error": "^1.0.0",
|
|
43
|
+
"happy-dom": "^14.0.0",
|
|
48
44
|
"lint-staged": "^15.0.0",
|
|
49
|
-
"nock": "
|
|
45
|
+
"nock": "14.0.0-beta.5",
|
|
50
46
|
"prettier": "^3.0.0",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"typescript": "^5.3.3"
|
|
47
|
+
"typescript": "^5.3.3",
|
|
48
|
+
"vitest": "^1.4.0"
|
|
54
49
|
},
|
|
55
50
|
"eslintConfig": {
|
|
56
51
|
"extends": "@silverhand"
|
|
@@ -65,7 +60,8 @@
|
|
|
65
60
|
"check": "tsc --noEmit",
|
|
66
61
|
"build": "rm -rf lib/ && tsc -p tsconfig.build.json --noEmit && rollup -c",
|
|
67
62
|
"lint": "eslint --ext .ts src",
|
|
68
|
-
"test": "
|
|
69
|
-
"test:
|
|
63
|
+
"test": "vitest",
|
|
64
|
+
"test:dom": "vitest --config=vitest.config.dom.ts",
|
|
65
|
+
"test:coverage": "pnpm test:dom --silent --no-watch && pnpm run test --no-watch --silent --coverage"
|
|
70
66
|
}
|
|
71
67
|
}
|