@logto/client 2.2.0 → 2.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/index.cjs +25 -16
- package/lib/index.d.ts +0 -1
- package/lib/index.js +25 -16
- package/package.json +5 -5
package/lib/index.cjs
CHANGED
|
@@ -105,25 +105,38 @@ class LogtoClient {
|
|
|
105
105
|
return `${origin}${pathname}` === redirectUri;
|
|
106
106
|
}
|
|
107
107
|
async handleSignInCallback(callbackUri) {
|
|
108
|
-
const {
|
|
109
|
-
const { requester } = adapter;
|
|
108
|
+
const { requester } = this.adapter;
|
|
110
109
|
const signInSession = await this.getSignInSession();
|
|
111
110
|
if (!signInSession) {
|
|
112
111
|
throw new errors.LogtoClientError('sign_in_session.not_found');
|
|
113
112
|
}
|
|
114
113
|
const { redirectUri, state, codeVerifier } = signInSession;
|
|
115
114
|
const code = js.verifyAndParseCodeFromCallbackUri(callbackUri, redirectUri, state);
|
|
116
|
-
|
|
115
|
+
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
116
|
+
const accessTokenKey = index$2.buildAccessTokenKey();
|
|
117
|
+
const { appId: clientId } = this.logtoConfig;
|
|
117
118
|
const { tokenEndpoint } = await this.getOidcConfig();
|
|
118
|
-
const
|
|
119
|
+
const requestedAt = Math.round(Date.now() / 1000);
|
|
120
|
+
const { idToken, refreshToken, accessToken, scope, expiresIn } = await js.fetchTokenByAuthorizationCode({
|
|
119
121
|
clientId,
|
|
120
122
|
tokenEndpoint,
|
|
121
123
|
redirectUri,
|
|
122
124
|
codeVerifier,
|
|
123
125
|
code,
|
|
124
126
|
}, requester);
|
|
125
|
-
await this.verifyIdToken(
|
|
126
|
-
await this.
|
|
127
|
+
await this.verifyIdToken(idToken);
|
|
128
|
+
await this.setRefreshToken(refreshToken ?? null);
|
|
129
|
+
await this.setIdToken(idToken);
|
|
130
|
+
this.accessTokenMap.set(accessTokenKey, {
|
|
131
|
+
token: accessToken,
|
|
132
|
+
scope,
|
|
133
|
+
/** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
|
|
134
|
+
* in the token claims. It is utilized by the client to determine if the cached access token
|
|
135
|
+
* has expired and when a new access token should be requested.
|
|
136
|
+
*/
|
|
137
|
+
expiresAt: requestedAt + expiresIn,
|
|
138
|
+
});
|
|
139
|
+
await this.saveAccessTokenMap();
|
|
127
140
|
await this.setSignInSession(null);
|
|
128
141
|
}
|
|
129
142
|
async signOut(postLogoutRedirectUri) {
|
|
@@ -177,6 +190,7 @@ class LogtoClient {
|
|
|
177
190
|
const accessTokenKey = index$2.buildAccessTokenKey(resource);
|
|
178
191
|
const { appId: clientId } = this.logtoConfig;
|
|
179
192
|
const { tokenEndpoint } = await this.getOidcConfig();
|
|
193
|
+
const requestedAt = Math.round(Date.now() / 1000);
|
|
180
194
|
const { accessToken, refreshToken, idToken, scope, expiresIn } = await js.fetchTokenByRefreshToken({
|
|
181
195
|
clientId,
|
|
182
196
|
tokenEndpoint,
|
|
@@ -186,7 +200,11 @@ class LogtoClient {
|
|
|
186
200
|
this.accessTokenMap.set(accessTokenKey, {
|
|
187
201
|
token: accessToken,
|
|
188
202
|
scope,
|
|
189
|
-
expiresAt
|
|
203
|
+
/** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
|
|
204
|
+
* in the token claims. It is utilized by the client to determine if the cached access token
|
|
205
|
+
* has expired and when a new access token should be requested.
|
|
206
|
+
*/
|
|
207
|
+
expiresAt: requestedAt + expiresIn,
|
|
190
208
|
});
|
|
191
209
|
await this.saveAccessTokenMap();
|
|
192
210
|
await this.setRefreshToken(refreshToken);
|
|
@@ -202,15 +220,6 @@ class LogtoClient {
|
|
|
202
220
|
const jwtVerifyGetKey = await this.getJwtVerifyGetKey();
|
|
203
221
|
await js.verifyIdToken(idToken, appId, issuer, jwtVerifyGetKey);
|
|
204
222
|
}
|
|
205
|
-
async saveCodeToken({ refreshToken, idToken, scope, accessToken, expiresIn, }) {
|
|
206
|
-
await this.setRefreshToken(refreshToken ?? null);
|
|
207
|
-
await this.setIdToken(idToken);
|
|
208
|
-
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
209
|
-
const accessTokenKey = index$2.buildAccessTokenKey();
|
|
210
|
-
const expiresAt = Date.now() / 1000 + expiresIn;
|
|
211
|
-
this.accessTokenMap.set(accessTokenKey, { token: accessToken, scope, expiresAt });
|
|
212
|
-
await this.saveAccessTokenMap();
|
|
213
|
-
}
|
|
214
223
|
async saveAccessTokenMap() {
|
|
215
224
|
const data = {};
|
|
216
225
|
for (const [key, accessToken] of this.accessTokenMap.entries()) {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -102,25 +102,38 @@ class LogtoClient {
|
|
|
102
102
|
return `${origin}${pathname}` === redirectUri;
|
|
103
103
|
}
|
|
104
104
|
async handleSignInCallback(callbackUri) {
|
|
105
|
-
const {
|
|
106
|
-
const { requester } = adapter;
|
|
105
|
+
const { requester } = this.adapter;
|
|
107
106
|
const signInSession = await this.getSignInSession();
|
|
108
107
|
if (!signInSession) {
|
|
109
108
|
throw new LogtoClientError('sign_in_session.not_found');
|
|
110
109
|
}
|
|
111
110
|
const { redirectUri, state, codeVerifier } = signInSession;
|
|
112
111
|
const code = verifyAndParseCodeFromCallbackUri(callbackUri, redirectUri, state);
|
|
113
|
-
|
|
112
|
+
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
113
|
+
const accessTokenKey = buildAccessTokenKey();
|
|
114
|
+
const { appId: clientId } = this.logtoConfig;
|
|
114
115
|
const { tokenEndpoint } = await this.getOidcConfig();
|
|
115
|
-
const
|
|
116
|
+
const requestedAt = Math.round(Date.now() / 1000);
|
|
117
|
+
const { idToken, refreshToken, accessToken, scope, expiresIn } = await fetchTokenByAuthorizationCode({
|
|
116
118
|
clientId,
|
|
117
119
|
tokenEndpoint,
|
|
118
120
|
redirectUri,
|
|
119
121
|
codeVerifier,
|
|
120
122
|
code,
|
|
121
123
|
}, requester);
|
|
122
|
-
await this.verifyIdToken(
|
|
123
|
-
await this.
|
|
124
|
+
await this.verifyIdToken(idToken);
|
|
125
|
+
await this.setRefreshToken(refreshToken ?? null);
|
|
126
|
+
await this.setIdToken(idToken);
|
|
127
|
+
this.accessTokenMap.set(accessTokenKey, {
|
|
128
|
+
token: accessToken,
|
|
129
|
+
scope,
|
|
130
|
+
/** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
|
|
131
|
+
* in the token claims. It is utilized by the client to determine if the cached access token
|
|
132
|
+
* has expired and when a new access token should be requested.
|
|
133
|
+
*/
|
|
134
|
+
expiresAt: requestedAt + expiresIn,
|
|
135
|
+
});
|
|
136
|
+
await this.saveAccessTokenMap();
|
|
124
137
|
await this.setSignInSession(null);
|
|
125
138
|
}
|
|
126
139
|
async signOut(postLogoutRedirectUri) {
|
|
@@ -174,6 +187,7 @@ class LogtoClient {
|
|
|
174
187
|
const accessTokenKey = buildAccessTokenKey(resource);
|
|
175
188
|
const { appId: clientId } = this.logtoConfig;
|
|
176
189
|
const { tokenEndpoint } = await this.getOidcConfig();
|
|
190
|
+
const requestedAt = Math.round(Date.now() / 1000);
|
|
177
191
|
const { accessToken, refreshToken, idToken, scope, expiresIn } = await fetchTokenByRefreshToken({
|
|
178
192
|
clientId,
|
|
179
193
|
tokenEndpoint,
|
|
@@ -183,7 +197,11 @@ class LogtoClient {
|
|
|
183
197
|
this.accessTokenMap.set(accessTokenKey, {
|
|
184
198
|
token: accessToken,
|
|
185
199
|
scope,
|
|
186
|
-
expiresAt
|
|
200
|
+
/** The `expiresAt` variable provides an approximate estimation of the actual `exp` property
|
|
201
|
+
* in the token claims. It is utilized by the client to determine if the cached access token
|
|
202
|
+
* has expired and when a new access token should be requested.
|
|
203
|
+
*/
|
|
204
|
+
expiresAt: requestedAt + expiresIn,
|
|
187
205
|
});
|
|
188
206
|
await this.saveAccessTokenMap();
|
|
189
207
|
await this.setRefreshToken(refreshToken);
|
|
@@ -199,15 +217,6 @@ class LogtoClient {
|
|
|
199
217
|
const jwtVerifyGetKey = await this.getJwtVerifyGetKey();
|
|
200
218
|
await verifyIdToken(idToken, appId, issuer, jwtVerifyGetKey);
|
|
201
219
|
}
|
|
202
|
-
async saveCodeToken({ refreshToken, idToken, scope, accessToken, expiresIn, }) {
|
|
203
|
-
await this.setRefreshToken(refreshToken ?? null);
|
|
204
|
-
await this.setIdToken(idToken);
|
|
205
|
-
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
206
|
-
const accessTokenKey = buildAccessTokenKey();
|
|
207
|
-
const expiresAt = Date.now() / 1000 + expiresIn;
|
|
208
|
-
this.accessTokenMap.set(accessTokenKey, { token: accessToken, scope, expiresAt });
|
|
209
|
-
await this.saveAccessTokenMap();
|
|
210
|
-
}
|
|
211
220
|
async saveAccessTokenMap() {
|
|
212
221
|
const data = {};
|
|
213
222
|
for (const [key, accessToken] of this.accessTokenMap.entries()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/client",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.cjs",
|
|
6
6
|
"module": "./lib/index.js",
|
|
@@ -27,18 +27,18 @@
|
|
|
27
27
|
"jose": "^4.13.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@silverhand/eslint-config": "^
|
|
31
|
-
"@silverhand/ts-config": "^
|
|
30
|
+
"@silverhand/eslint-config": "^4.0.1",
|
|
31
|
+
"@silverhand/ts-config": "^4.0.0",
|
|
32
32
|
"@swc/core": "^1.3.50",
|
|
33
33
|
"@swc/jest": "^0.2.24",
|
|
34
34
|
"@types/jest": "^29.5.0",
|
|
35
35
|
"@types/node": "^18.0.0",
|
|
36
|
-
"eslint": "^8.
|
|
36
|
+
"eslint": "^8.44.0",
|
|
37
37
|
"jest": "^29.5.0",
|
|
38
38
|
"jest-matcher-specific-error": "^1.0.0",
|
|
39
39
|
"lint-staged": "^13.0.0",
|
|
40
40
|
"nock": "^13.3.0",
|
|
41
|
-
"prettier": "^
|
|
41
|
+
"prettier": "^3.0.0",
|
|
42
42
|
"text-encoder": "^0.0.4",
|
|
43
43
|
"type-fest": "^3.0.0",
|
|
44
44
|
"typescript": "^5.0.0"
|