@logto/client 2.6.3 → 2.6.5
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/client.cjs +12 -7
- package/lib/client.d.ts +9 -1
- package/lib/client.js +12 -7
- package/package.json +1 -1
package/lib/client.cjs
CHANGED
|
@@ -57,6 +57,10 @@ class StandardLogtoClient {
|
|
|
57
57
|
* It uses the same refresh strategy as {@link getAccessToken}.
|
|
58
58
|
*/
|
|
59
59
|
this.getOrganizationToken = memoize.memoize(this.#getOrganizationToken);
|
|
60
|
+
/**
|
|
61
|
+
* Clear the access token from the cache storage.
|
|
62
|
+
*/
|
|
63
|
+
this.clearAccessToken = memoize.memoize(this.#clearAccessToken);
|
|
60
64
|
/**
|
|
61
65
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
62
66
|
* callback URI and exchanging it for the tokens.
|
|
@@ -141,7 +145,7 @@ class StandardLogtoClient {
|
|
|
141
145
|
return js.fetchUserInfo(userinfoEndpoint, accessToken, this.adapter.requester);
|
|
142
146
|
}
|
|
143
147
|
async signIn(options, mode, hint) {
|
|
144
|
-
const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, interactionMode, loginHint, directSignIn, extraParams, } = typeof options === 'string' || options instanceof URL
|
|
148
|
+
const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, interactionMode, loginHint, directSignIn, extraParams, prompt, } = typeof options === 'string' || options instanceof URL
|
|
145
149
|
? {
|
|
146
150
|
redirectUri: options,
|
|
147
151
|
postRedirectUri: undefined,
|
|
@@ -150,11 +154,12 @@ class StandardLogtoClient {
|
|
|
150
154
|
loginHint: hint,
|
|
151
155
|
directSignIn: undefined,
|
|
152
156
|
extraParams: undefined,
|
|
157
|
+
prompt: undefined,
|
|
153
158
|
}
|
|
154
159
|
: options;
|
|
155
160
|
const redirectUri = redirectUriUrl.toString();
|
|
156
161
|
const postRedirectUri = postRedirectUriUrl?.toString();
|
|
157
|
-
const { appId: clientId, prompt, resources, scopes } = this.logtoConfig;
|
|
162
|
+
const { appId: clientId, prompt: promptViaConfig, resources, scopes } = this.logtoConfig;
|
|
158
163
|
const { authorizationEndpoint } = await this.getOidcConfig();
|
|
159
164
|
const [codeVerifier, state] = await Promise.all([
|
|
160
165
|
this.adapter.generateCodeVerifier(),
|
|
@@ -169,7 +174,7 @@ class StandardLogtoClient {
|
|
|
169
174
|
state,
|
|
170
175
|
scopes,
|
|
171
176
|
resources,
|
|
172
|
-
prompt,
|
|
177
|
+
prompt: prompt ?? promptViaConfig,
|
|
173
178
|
firstScreen,
|
|
174
179
|
interactionMode,
|
|
175
180
|
loginHint,
|
|
@@ -251,10 +256,6 @@ class StandardLogtoClient {
|
|
|
251
256
|
async setRefreshToken(value) {
|
|
252
257
|
return this.adapter.setStorageItem(types.PersistKey.RefreshToken, value);
|
|
253
258
|
}
|
|
254
|
-
async clearAccessToken() {
|
|
255
|
-
this.accessTokenMap.clear();
|
|
256
|
-
await this.adapter.storage.removeItem('accessToken');
|
|
257
|
-
}
|
|
258
259
|
async getAccessTokenByRefreshToken(resource, organizationId) {
|
|
259
260
|
const currentRefreshToken = await this.getRefreshToken();
|
|
260
261
|
if (!currentRefreshToken) {
|
|
@@ -346,6 +347,10 @@ class StandardLogtoClient {
|
|
|
346
347
|
}
|
|
347
348
|
return this.getAccessToken(undefined, organizationId);
|
|
348
349
|
}
|
|
350
|
+
async #clearAccessToken() {
|
|
351
|
+
this.accessTokenMap.clear();
|
|
352
|
+
await this.adapter.storage.removeItem('accessToken');
|
|
353
|
+
}
|
|
349
354
|
async #handleSignInCallback(callbackUri) {
|
|
350
355
|
const signInSession = await this.getSignInSession();
|
|
351
356
|
if (!signInSession) {
|
package/lib/client.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ export type SignInOptions = {
|
|
|
12
12
|
* sign-in callback. If not specified, the user will stay on the `redirectUri` page.
|
|
13
13
|
*/
|
|
14
14
|
postRedirectUri?: string | URL;
|
|
15
|
+
/**
|
|
16
|
+
* The prompt parameter to be used for the authorization request.
|
|
17
|
+
* Note: If specified, it will override the prompt value in Logto configs.
|
|
18
|
+
*/
|
|
19
|
+
prompt?: SignInUriParameters['prompt'];
|
|
15
20
|
} & Pick<SignInUriParameters, 'interactionMode' | 'firstScreen' | 'loginHint' | 'directSignIn' | 'extraParams'>;
|
|
16
21
|
/**
|
|
17
22
|
* The Logto base client class that provides the essential methods for
|
|
@@ -61,6 +66,10 @@ export declare class StandardLogtoClient {
|
|
|
61
66
|
* It uses the same refresh strategy as {@link getAccessToken}.
|
|
62
67
|
*/
|
|
63
68
|
readonly getOrganizationToken: (this: unknown, organizationId: string) => Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Clear the access token from the cache storage.
|
|
71
|
+
*/
|
|
72
|
+
readonly clearAccessToken: (this: unknown) => Promise<void>;
|
|
64
73
|
/**
|
|
65
74
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
66
75
|
* callback URI and exchanging it for the tokens.
|
|
@@ -183,7 +192,6 @@ export declare class StandardLogtoClient {
|
|
|
183
192
|
protected setSignInSession(value: Nullable<LogtoSignInSessionItem>): Promise<void>;
|
|
184
193
|
private setIdToken;
|
|
185
194
|
private setRefreshToken;
|
|
186
|
-
private clearAccessToken;
|
|
187
195
|
private getAccessTokenByRefreshToken;
|
|
188
196
|
private saveAccessTokenMap;
|
|
189
197
|
private loadAccessTokenMap;
|
package/lib/client.js
CHANGED
|
@@ -55,6 +55,10 @@ class StandardLogtoClient {
|
|
|
55
55
|
* It uses the same refresh strategy as {@link getAccessToken}.
|
|
56
56
|
*/
|
|
57
57
|
this.getOrganizationToken = memoize(this.#getOrganizationToken);
|
|
58
|
+
/**
|
|
59
|
+
* Clear the access token from the cache storage.
|
|
60
|
+
*/
|
|
61
|
+
this.clearAccessToken = memoize(this.#clearAccessToken);
|
|
58
62
|
/**
|
|
59
63
|
* Handle the sign-in callback by parsing the authorization code from the
|
|
60
64
|
* callback URI and exchanging it for the tokens.
|
|
@@ -139,7 +143,7 @@ class StandardLogtoClient {
|
|
|
139
143
|
return fetchUserInfo(userinfoEndpoint, accessToken, this.adapter.requester);
|
|
140
144
|
}
|
|
141
145
|
async signIn(options, mode, hint) {
|
|
142
|
-
const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, interactionMode, loginHint, directSignIn, extraParams, } = typeof options === 'string' || options instanceof URL
|
|
146
|
+
const { redirectUri: redirectUriUrl, postRedirectUri: postRedirectUriUrl, firstScreen, interactionMode, loginHint, directSignIn, extraParams, prompt, } = typeof options === 'string' || options instanceof URL
|
|
143
147
|
? {
|
|
144
148
|
redirectUri: options,
|
|
145
149
|
postRedirectUri: undefined,
|
|
@@ -148,11 +152,12 @@ class StandardLogtoClient {
|
|
|
148
152
|
loginHint: hint,
|
|
149
153
|
directSignIn: undefined,
|
|
150
154
|
extraParams: undefined,
|
|
155
|
+
prompt: undefined,
|
|
151
156
|
}
|
|
152
157
|
: options;
|
|
153
158
|
const redirectUri = redirectUriUrl.toString();
|
|
154
159
|
const postRedirectUri = postRedirectUriUrl?.toString();
|
|
155
|
-
const { appId: clientId, prompt, resources, scopes } = this.logtoConfig;
|
|
160
|
+
const { appId: clientId, prompt: promptViaConfig, resources, scopes } = this.logtoConfig;
|
|
156
161
|
const { authorizationEndpoint } = await this.getOidcConfig();
|
|
157
162
|
const [codeVerifier, state] = await Promise.all([
|
|
158
163
|
this.adapter.generateCodeVerifier(),
|
|
@@ -167,7 +172,7 @@ class StandardLogtoClient {
|
|
|
167
172
|
state,
|
|
168
173
|
scopes,
|
|
169
174
|
resources,
|
|
170
|
-
prompt,
|
|
175
|
+
prompt: prompt ?? promptViaConfig,
|
|
171
176
|
firstScreen,
|
|
172
177
|
interactionMode,
|
|
173
178
|
loginHint,
|
|
@@ -249,10 +254,6 @@ class StandardLogtoClient {
|
|
|
249
254
|
async setRefreshToken(value) {
|
|
250
255
|
return this.adapter.setStorageItem(PersistKey.RefreshToken, value);
|
|
251
256
|
}
|
|
252
|
-
async clearAccessToken() {
|
|
253
|
-
this.accessTokenMap.clear();
|
|
254
|
-
await this.adapter.storage.removeItem('accessToken');
|
|
255
|
-
}
|
|
256
257
|
async getAccessTokenByRefreshToken(resource, organizationId) {
|
|
257
258
|
const currentRefreshToken = await this.getRefreshToken();
|
|
258
259
|
if (!currentRefreshToken) {
|
|
@@ -344,6 +345,10 @@ class StandardLogtoClient {
|
|
|
344
345
|
}
|
|
345
346
|
return this.getAccessToken(undefined, organizationId);
|
|
346
347
|
}
|
|
348
|
+
async #clearAccessToken() {
|
|
349
|
+
this.accessTokenMap.clear();
|
|
350
|
+
await this.adapter.storage.removeItem('accessToken');
|
|
351
|
+
}
|
|
347
352
|
async #handleSignInCallback(callbackUri) {
|
|
348
353
|
const signInSession = await this.getSignInSession();
|
|
349
354
|
if (!signInSession) {
|