@logto/client 1.1.1 → 1.1.2
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.d.ts +17 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.js +33 -0
- package/lib/errors.mjs +27 -0
- package/lib/index.d.ts +27 -56
- package/lib/index.js +172 -226
- package/lib/index.mjs +254 -0
- package/lib/index.test.d.ts +1 -0
- package/lib/mock.d.ts +68 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/index.js +26 -0
- package/lib/types/index.mjs +23 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +9 -0
- package/lib/utils/index.mjs +6 -0
- package/lib/utils/index.test.d.ts +1 -0
- package/lib/utils/requester.d.ts +2 -0
- package/lib/utils/requester.js +21 -0
- package/lib/utils/requester.mjs +19 -0
- package/lib/utils/requester.test.d.ts +1 -0
- package/package.json +17 -20
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/module.d.mts +0 -76
- package/lib/module.mjs +0 -309
- package/lib/module.mjs.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,285 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
var $4R6L3$jose = require("jose");
|
|
3
|
-
var $4R6L3$lodashonce = require("lodash.once");
|
|
4
|
-
var $4R6L3$lodashget = require("lodash.get");
|
|
5
|
-
|
|
6
|
-
function $parcel$interopDefault(a) {
|
|
7
|
-
return a && a.__esModule ? a.default : a;
|
|
8
|
-
}
|
|
9
|
-
function $parcel$defineInteropFlag(a) {
|
|
10
|
-
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
11
|
-
}
|
|
12
|
-
function $parcel$exportWildcard(dest, source) {
|
|
13
|
-
Object.keys(source).forEach(function(key) {
|
|
14
|
-
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Object.defineProperty(dest, key, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return source[key];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return dest;
|
|
27
|
-
}
|
|
28
|
-
function $parcel$export(e, n, v, s) {
|
|
29
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
$parcel$defineInteropFlag(module.exports);
|
|
33
|
-
|
|
34
|
-
$parcel$export(module.exports, "default", () => $f73788ae50447ce9$export$2e2bcd8739ae039);
|
|
35
|
-
$parcel$export(module.exports, "LogtoError", () => $f73788ae50447ce9$re_export$LogtoError);
|
|
36
|
-
$parcel$export(module.exports, "OidcError", () => $f73788ae50447ce9$re_export$OidcError);
|
|
37
|
-
$parcel$export(module.exports, "Prompt", () => $4R6L3$logtojs.Prompt);
|
|
38
|
-
$parcel$export(module.exports, "LogtoRequestError", () => $f73788ae50447ce9$re_export$LogtoRequestError);
|
|
39
|
-
$parcel$export(module.exports, "ReservedScope", () => $f73788ae50447ce9$re_export$ReservedScope);
|
|
40
|
-
$parcel$export(module.exports, "UserScope", () => $f73788ae50447ce9$re_export$UserScope);
|
|
41
|
-
$parcel$export(module.exports, "createRequester", () => $b455f57f80fbf6bf$export$8d54726fdbf08e0a);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var $9166104b36889c59$exports = {};
|
|
46
|
-
|
|
47
|
-
$parcel$export($9166104b36889c59$exports, "LogtoClientError", () => $9166104b36889c59$export$877962ca249b8fc8);
|
|
48
|
-
|
|
49
|
-
const $9166104b36889c59$var$logtoClientErrorCodes = Object.freeze({
|
|
50
|
-
sign_in_session: {
|
|
51
|
-
invalid: "Invalid sign-in session.",
|
|
52
|
-
not_found: "Sign-in session not found."
|
|
53
|
-
},
|
|
54
|
-
not_authenticated: "Not authenticated.",
|
|
55
|
-
fetch_user_info_failed: "Unable to fetch user info. The access token may be invalid."
|
|
56
|
-
});
|
|
57
|
-
const $9166104b36889c59$var$getMessageByErrorCode = (errorCode)=>{
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
59
|
-
const message = (0, ($parcel$interopDefault($4R6L3$lodashget)))($9166104b36889c59$var$logtoClientErrorCodes, errorCode);
|
|
60
|
-
if (typeof message === "string") return message;
|
|
61
|
-
return errorCode;
|
|
62
|
-
};
|
|
63
|
-
class $9166104b36889c59$export$877962ca249b8fc8 extends Error {
|
|
64
|
-
constructor(code, data){
|
|
65
|
-
super($9166104b36889c59$var$getMessageByErrorCode(code));
|
|
66
|
-
this.code = code;
|
|
67
|
-
this.data = data;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var $6d3989f7f53311af$exports = {};
|
|
73
|
-
|
|
74
|
-
$parcel$export($6d3989f7f53311af$exports, "isLogtoSignInSessionItem", () => $6d3989f7f53311af$export$5d8adf6e063019de);
|
|
75
|
-
$parcel$export($6d3989f7f53311af$exports, "isLogtoAccessTokenMap", () => $6d3989f7f53311af$export$c12fab42a9a3e2a6);
|
|
76
|
-
|
|
77
|
-
const $6d3989f7f53311af$export$5d8adf6e063019de = (data)=>{
|
|
78
|
-
if (!(0, $4R6L3$logtojs.isArbitraryObject)(data)) return false;
|
|
79
|
-
return [
|
|
80
|
-
"redirectUri",
|
|
81
|
-
"codeVerifier",
|
|
82
|
-
"state"
|
|
83
|
-
].every((key)=>typeof data[key] === "string");
|
|
84
|
-
};
|
|
85
|
-
const $6d3989f7f53311af$export$c12fab42a9a3e2a6 = (data)=>{
|
|
86
|
-
if (!(0, $4R6L3$logtojs.isArbitraryObject)(data)) return false;
|
|
87
|
-
return Object.values(data).every((value)=>{
|
|
88
|
-
if (!(0, $4R6L3$logtojs.isArbitraryObject)(value)) return false;
|
|
89
|
-
return typeof value.token === "string" && typeof value.scope === "string" && typeof value.expiresAt === "number";
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const $b455f57f80fbf6bf$export$8d54726fdbf08e0a = (fetchFunction)=>{
|
|
97
|
-
return async (...args)=>{
|
|
98
|
-
const response = await fetchFunction(...args);
|
|
99
|
-
if (!response.ok) {
|
|
100
|
-
const responseJson = await response.json();
|
|
101
|
-
if (!(0, $4R6L3$logtojs.isLogtoRequestError)(responseJson)) throw new (0, $4R6L3$logtojs.LogtoError)("unexpected_response_error", responseJson);
|
|
102
|
-
// Expected request error from server
|
|
103
|
-
const { code: code , message: message } = responseJson;
|
|
104
|
-
throw new (0, $4R6L3$logtojs.LogtoRequestError)(code, message);
|
|
105
|
-
}
|
|
106
|
-
return response.json();
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const $e2aabdbdb3cc09f0$export$8f595bd2a47bcea6 = (resource = "", scopes = [])=>`${scopes.slice().sort().join(" ")}@${resource}`;
|
|
112
|
-
const $e2aabdbdb3cc09f0$export$5d9c34f69c80822b = (endpoint)=>new URL((0, $4R6L3$logtojs.discoveryPath), endpoint).toString();
|
|
1
|
+
'use strict';
|
|
113
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
114
4
|
|
|
5
|
+
var js = require('@logto/js');
|
|
6
|
+
var jose = require('jose');
|
|
7
|
+
var once = require('lodash.once');
|
|
8
|
+
var errors = require('./errors.js');
|
|
9
|
+
var index = require('./types/index.js');
|
|
10
|
+
var index$1 = require('./utils/index.js');
|
|
11
|
+
var requester = require('./utils/requester.js');
|
|
115
12
|
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
116
14
|
|
|
15
|
+
var once__default = /*#__PURE__*/_interopDefault(once);
|
|
117
16
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
constructor(logtoConfig, adapter){
|
|
17
|
+
class LogtoClient {
|
|
18
|
+
constructor(logtoConfig, adapter) {
|
|
19
|
+
this.getOidcConfig = once__default.default(this._getOidcConfig);
|
|
20
|
+
this.getJwtVerifyGetKey = once__default.default(this._getJwtVerifyGetKey);
|
|
21
|
+
this.accessTokenMap = new Map();
|
|
124
22
|
this.logtoConfig = {
|
|
125
23
|
...logtoConfig,
|
|
126
|
-
prompt: logtoConfig.prompt ??
|
|
127
|
-
scopes:
|
|
24
|
+
prompt: logtoConfig.prompt ?? js.Prompt.Consent,
|
|
25
|
+
scopes: js.withDefaultScopes(logtoConfig.scopes).split(' '),
|
|
128
26
|
};
|
|
129
27
|
this.adapter = adapter;
|
|
130
|
-
this.loadAccessTokenMap();
|
|
28
|
+
void this.loadAccessTokenMap();
|
|
131
29
|
}
|
|
132
30
|
async isAuthenticated() {
|
|
133
31
|
return Boolean(await this.getIdToken());
|
|
134
32
|
}
|
|
135
33
|
async getRefreshToken() {
|
|
136
|
-
return this.adapter.storage.getItem(
|
|
34
|
+
return this.adapter.storage.getItem('refreshToken');
|
|
137
35
|
}
|
|
138
36
|
async getIdToken() {
|
|
139
|
-
return this.adapter.storage.getItem(
|
|
37
|
+
return this.adapter.storage.getItem('idToken');
|
|
140
38
|
}
|
|
141
39
|
async getAccessToken(resource) {
|
|
142
|
-
if (!await this.getIdToken())
|
|
143
|
-
|
|
40
|
+
if (!(await this.getIdToken())) {
|
|
41
|
+
throw new errors.LogtoClientError('not_authenticated');
|
|
42
|
+
}
|
|
43
|
+
const accessTokenKey = index$1.buildAccessTokenKey(resource);
|
|
144
44
|
const accessToken = this.accessTokenMap.get(accessTokenKey);
|
|
145
|
-
if (accessToken && accessToken.expiresAt > Date.now() / 1000)
|
|
45
|
+
if (accessToken && accessToken.expiresAt > Date.now() / 1000) {
|
|
46
|
+
return accessToken.token;
|
|
47
|
+
}
|
|
146
48
|
// Since the access token has expired, delete it from the map.
|
|
147
|
-
if (accessToken)
|
|
49
|
+
if (accessToken) {
|
|
50
|
+
this.accessTokenMap.delete(accessTokenKey);
|
|
51
|
+
}
|
|
148
52
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
53
|
+
* Need to fetch a new access token using refresh token.
|
|
54
|
+
*/
|
|
55
|
+
return this.getAccessTokenByRefreshToken(resource);
|
|
151
56
|
}
|
|
152
57
|
async getIdTokenClaims() {
|
|
153
58
|
const idToken = await this.getIdToken();
|
|
154
|
-
if (!idToken)
|
|
155
|
-
|
|
59
|
+
if (!idToken) {
|
|
60
|
+
throw new errors.LogtoClientError('not_authenticated');
|
|
61
|
+
}
|
|
62
|
+
return js.decodeIdToken(idToken);
|
|
156
63
|
}
|
|
157
64
|
async fetchUserInfo() {
|
|
158
|
-
const { userinfoEndpoint
|
|
65
|
+
const { userinfoEndpoint } = await this.getOidcConfig();
|
|
159
66
|
const accessToken = await this.getAccessToken();
|
|
160
|
-
if (!accessToken)
|
|
161
|
-
|
|
67
|
+
if (!accessToken) {
|
|
68
|
+
throw new errors.LogtoClientError('fetch_user_info_failed');
|
|
69
|
+
}
|
|
70
|
+
return js.fetchUserInfo(userinfoEndpoint, accessToken, this.adapter.requester);
|
|
162
71
|
}
|
|
163
72
|
async signIn(redirectUri, interactionMode) {
|
|
164
|
-
const { appId: clientId
|
|
165
|
-
const { authorizationEndpoint
|
|
73
|
+
const { appId: clientId, prompt, resources, scopes } = this.logtoConfig;
|
|
74
|
+
const { authorizationEndpoint } = await this.getOidcConfig();
|
|
166
75
|
const codeVerifier = this.adapter.generateCodeVerifier();
|
|
167
76
|
const codeChallenge = await this.adapter.generateCodeChallenge(codeVerifier);
|
|
168
77
|
const state = this.adapter.generateState();
|
|
169
|
-
const signInUri =
|
|
170
|
-
authorizationEndpoint
|
|
171
|
-
clientId
|
|
172
|
-
redirectUri
|
|
173
|
-
codeChallenge
|
|
174
|
-
state
|
|
175
|
-
scopes
|
|
176
|
-
resources
|
|
177
|
-
prompt
|
|
178
|
-
interactionMode
|
|
179
|
-
});
|
|
180
|
-
await this.setSignInSession({
|
|
181
|
-
redirectUri: redirectUri,
|
|
182
|
-
codeVerifier: codeVerifier,
|
|
183
|
-
state: state
|
|
78
|
+
const signInUri = js.generateSignInUri({
|
|
79
|
+
authorizationEndpoint,
|
|
80
|
+
clientId,
|
|
81
|
+
redirectUri,
|
|
82
|
+
codeChallenge,
|
|
83
|
+
state,
|
|
84
|
+
scopes,
|
|
85
|
+
resources,
|
|
86
|
+
prompt,
|
|
87
|
+
interactionMode,
|
|
184
88
|
});
|
|
89
|
+
await this.setSignInSession({ redirectUri, codeVerifier, state });
|
|
185
90
|
await this.setRefreshToken(null);
|
|
186
91
|
await this.setIdToken(null);
|
|
187
92
|
this.adapter.navigate(signInUri);
|
|
188
93
|
}
|
|
189
94
|
async isSignInRedirected(url) {
|
|
190
95
|
const signInSession = await this.getSignInSession();
|
|
191
|
-
if (!signInSession)
|
|
192
|
-
|
|
193
|
-
|
|
96
|
+
if (!signInSession) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
const { redirectUri } = signInSession;
|
|
100
|
+
const { origin, pathname } = new URL(url);
|
|
194
101
|
return `${origin}${pathname}` === redirectUri;
|
|
195
102
|
}
|
|
196
103
|
async handleSignInCallback(callbackUri) {
|
|
197
|
-
const { logtoConfig
|
|
198
|
-
const { requester
|
|
104
|
+
const { logtoConfig, adapter } = this;
|
|
105
|
+
const { requester } = adapter;
|
|
199
106
|
const signInSession = await this.getSignInSession();
|
|
200
|
-
if (!signInSession)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const {
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
107
|
+
if (!signInSession) {
|
|
108
|
+
throw new errors.LogtoClientError('sign_in_session.not_found');
|
|
109
|
+
}
|
|
110
|
+
const { redirectUri, state, codeVerifier } = signInSession;
|
|
111
|
+
const code = js.verifyAndParseCodeFromCallbackUri(callbackUri, redirectUri, state);
|
|
112
|
+
const { appId: clientId } = logtoConfig;
|
|
113
|
+
const { tokenEndpoint } = await this.getOidcConfig();
|
|
114
|
+
const codeTokenResponse = await js.fetchTokenByAuthorizationCode({
|
|
115
|
+
clientId,
|
|
116
|
+
tokenEndpoint,
|
|
117
|
+
redirectUri,
|
|
118
|
+
codeVerifier,
|
|
119
|
+
code,
|
|
211
120
|
}, requester);
|
|
212
121
|
await this.verifyIdToken(codeTokenResponse.idToken);
|
|
213
122
|
await this.saveCodeToken(codeTokenResponse);
|
|
214
123
|
await this.setSignInSession(null);
|
|
215
124
|
}
|
|
216
125
|
async signOut(postLogoutRedirectUri) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
const { appId: clientId } = this.logtoConfig;
|
|
220
|
-
const { endSessionEndpoint: endSessionEndpoint , revocationEndpoint: revocationEndpoint } = await this.getOidcConfig();
|
|
126
|
+
const { appId: clientId } = this.logtoConfig;
|
|
127
|
+
const { endSessionEndpoint, revocationEndpoint } = await this.getOidcConfig();
|
|
221
128
|
const refreshToken = await this.getRefreshToken();
|
|
222
|
-
if (refreshToken)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
129
|
+
if (refreshToken) {
|
|
130
|
+
try {
|
|
131
|
+
await js.revoke(revocationEndpoint, clientId, refreshToken, this.adapter.requester);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Do nothing at this point, as we don't want to break the sign-out flow even if the revocation is failed
|
|
135
|
+
}
|
|
226
136
|
}
|
|
227
|
-
const url =
|
|
228
|
-
endSessionEndpoint
|
|
229
|
-
postLogoutRedirectUri
|
|
230
|
-
clientId
|
|
137
|
+
const url = js.generateSignOutUri({
|
|
138
|
+
endSessionEndpoint,
|
|
139
|
+
postLogoutRedirectUri,
|
|
140
|
+
clientId,
|
|
231
141
|
});
|
|
232
142
|
this.accessTokenMap.clear();
|
|
233
143
|
await this.setRefreshToken(null);
|
|
234
144
|
await this.setIdToken(null);
|
|
235
|
-
await this.adapter.storage.removeItem(
|
|
145
|
+
await this.adapter.storage.removeItem('accessToken');
|
|
236
146
|
this.adapter.navigate(url);
|
|
237
147
|
}
|
|
238
148
|
async getSignInSession() {
|
|
239
|
-
const jsonItem = await this.adapter.storage.getItem(
|
|
240
|
-
if (!jsonItem)
|
|
149
|
+
const jsonItem = await this.adapter.storage.getItem('signInSession');
|
|
150
|
+
if (!jsonItem) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
241
153
|
const item = JSON.parse(jsonItem);
|
|
242
|
-
if (!(
|
|
154
|
+
if (!index.isLogtoSignInSessionItem(item)) {
|
|
155
|
+
throw new errors.LogtoClientError('sign_in_session.invalid');
|
|
156
|
+
}
|
|
243
157
|
return item;
|
|
244
158
|
}
|
|
245
159
|
async setSignInSession(logtoSignInSessionItem) {
|
|
246
160
|
if (!logtoSignInSessionItem) {
|
|
247
|
-
await this.adapter.storage.removeItem(
|
|
161
|
+
await this.adapter.storage.removeItem('signInSession');
|
|
248
162
|
return;
|
|
249
163
|
}
|
|
250
164
|
const jsonItem = JSON.stringify(logtoSignInSessionItem);
|
|
251
|
-
await this.adapter.storage.setItem(
|
|
165
|
+
await this.adapter.storage.setItem('signInSession', jsonItem);
|
|
252
166
|
}
|
|
253
167
|
async setIdToken(idToken) {
|
|
254
168
|
if (!idToken) {
|
|
255
|
-
await this.adapter.storage.removeItem(
|
|
169
|
+
await this.adapter.storage.removeItem('idToken');
|
|
256
170
|
return;
|
|
257
171
|
}
|
|
258
|
-
await this.adapter.storage.setItem(
|
|
172
|
+
await this.adapter.storage.setItem('idToken', idToken);
|
|
259
173
|
}
|
|
260
174
|
async setRefreshToken(refreshToken) {
|
|
261
175
|
if (!refreshToken) {
|
|
262
|
-
await this.adapter.storage.removeItem(
|
|
176
|
+
await this.adapter.storage.removeItem('refreshToken');
|
|
263
177
|
return;
|
|
264
178
|
}
|
|
265
|
-
await this.adapter.storage.setItem(
|
|
179
|
+
await this.adapter.storage.setItem('refreshToken', refreshToken);
|
|
266
180
|
}
|
|
267
181
|
async getAccessTokenByRefreshToken(resource) {
|
|
268
182
|
const currentRefreshToken = await this.getRefreshToken();
|
|
269
|
-
if (!currentRefreshToken)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
const {
|
|
274
|
-
|
|
275
|
-
|
|
183
|
+
if (!currentRefreshToken) {
|
|
184
|
+
throw new errors.LogtoClientError('not_authenticated');
|
|
185
|
+
}
|
|
186
|
+
const accessTokenKey = index$1.buildAccessTokenKey(resource);
|
|
187
|
+
const { appId: clientId } = this.logtoConfig;
|
|
188
|
+
const { tokenEndpoint } = await this.getOidcConfig();
|
|
189
|
+
const { accessToken, refreshToken, idToken, scope, expiresIn } = await js.fetchTokenByRefreshToken({
|
|
190
|
+
clientId,
|
|
191
|
+
tokenEndpoint,
|
|
276
192
|
refreshToken: currentRefreshToken,
|
|
277
|
-
resource
|
|
193
|
+
resource,
|
|
278
194
|
}, this.adapter.requester);
|
|
279
195
|
this.accessTokenMap.set(accessTokenKey, {
|
|
280
196
|
token: accessToken,
|
|
281
|
-
scope
|
|
282
|
-
expiresAt: Math.round(Date.now() / 1000) + expiresIn
|
|
197
|
+
scope,
|
|
198
|
+
expiresAt: Math.round(Date.now() / 1000) + expiresIn,
|
|
283
199
|
});
|
|
284
200
|
await this.saveAccessTokenMap();
|
|
285
201
|
await this.setRefreshToken(refreshToken);
|
|
@@ -290,54 +206,84 @@ class $f73788ae50447ce9$export$2e2bcd8739ae039 {
|
|
|
290
206
|
return accessToken;
|
|
291
207
|
}
|
|
292
208
|
async _getOidcConfig() {
|
|
293
|
-
const { endpoint
|
|
294
|
-
const discoveryEndpoint =
|
|
295
|
-
return
|
|
209
|
+
const { endpoint } = this.logtoConfig;
|
|
210
|
+
const discoveryEndpoint = index$1.getDiscoveryEndpoint(endpoint);
|
|
211
|
+
return js.fetchOidcConfig(discoveryEndpoint, this.adapter.requester);
|
|
296
212
|
}
|
|
297
213
|
async _getJwtVerifyGetKey() {
|
|
298
|
-
const { jwksUri
|
|
299
|
-
return
|
|
214
|
+
const { jwksUri } = await this.getOidcConfig();
|
|
215
|
+
return jose.createRemoteJWKSet(new URL(jwksUri));
|
|
300
216
|
}
|
|
301
217
|
async verifyIdToken(idToken) {
|
|
302
|
-
const { appId
|
|
303
|
-
const { issuer
|
|
218
|
+
const { appId } = this.logtoConfig;
|
|
219
|
+
const { issuer } = await this.getOidcConfig();
|
|
304
220
|
const jwtVerifyGetKey = await this.getJwtVerifyGetKey();
|
|
305
|
-
await
|
|
221
|
+
await js.verifyIdToken(idToken, appId, issuer, jwtVerifyGetKey);
|
|
306
222
|
}
|
|
307
|
-
async saveCodeToken({ refreshToken
|
|
223
|
+
async saveCodeToken({ refreshToken, idToken, scope, accessToken, expiresIn, }) {
|
|
308
224
|
await this.setRefreshToken(refreshToken ?? null);
|
|
309
225
|
await this.setIdToken(idToken);
|
|
310
226
|
// NOTE: Will add scope to accessTokenKey when needed. (Linear issue LOG-1589)
|
|
311
|
-
const accessTokenKey =
|
|
227
|
+
const accessTokenKey = index$1.buildAccessTokenKey();
|
|
312
228
|
const expiresAt = Date.now() / 1000 + expiresIn;
|
|
313
|
-
this.accessTokenMap.set(accessTokenKey, {
|
|
314
|
-
token: accessToken,
|
|
315
|
-
scope: scope,
|
|
316
|
-
expiresAt: expiresAt
|
|
317
|
-
});
|
|
229
|
+
this.accessTokenMap.set(accessTokenKey, { token: accessToken, scope, expiresAt });
|
|
318
230
|
await this.saveAccessTokenMap();
|
|
319
231
|
}
|
|
320
232
|
async saveAccessTokenMap() {
|
|
321
233
|
const data = {};
|
|
322
|
-
for (const [key, accessToken] of this.accessTokenMap.entries())
|
|
323
|
-
|
|
324
|
-
|
|
234
|
+
for (const [key, accessToken] of this.accessTokenMap.entries()) {
|
|
235
|
+
// eslint-disable-next-line @silverhand/fp/no-mutation
|
|
236
|
+
data[key] = accessToken;
|
|
237
|
+
}
|
|
238
|
+
await this.adapter.storage.setItem('accessToken', JSON.stringify(data));
|
|
325
239
|
}
|
|
326
240
|
async loadAccessTokenMap() {
|
|
327
|
-
const raw = await this.adapter.storage.getItem(
|
|
328
|
-
if (!raw)
|
|
241
|
+
const raw = await this.adapter.storage.getItem('accessToken');
|
|
242
|
+
if (!raw) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
329
245
|
try {
|
|
330
246
|
const json = JSON.parse(raw);
|
|
331
|
-
if (!(
|
|
247
|
+
if (!index.isLogtoAccessTokenMap(json)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
332
250
|
this.accessTokenMap.clear();
|
|
333
|
-
for (const [key, accessToken] of Object.entries(json))
|
|
334
|
-
|
|
251
|
+
for (const [key, accessToken] of Object.entries(json)) {
|
|
252
|
+
this.accessTokenMap.set(key, accessToken);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
335
256
|
console.warn(error);
|
|
336
257
|
}
|
|
337
258
|
}
|
|
338
259
|
}
|
|
339
|
-
$parcel$exportWildcard(module.exports, $9166104b36889c59$exports);
|
|
340
|
-
$parcel$exportWildcard(module.exports, $6d3989f7f53311af$exports);
|
|
341
260
|
|
|
342
|
-
|
|
343
|
-
|
|
261
|
+
Object.defineProperty(exports, 'LogtoError', {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
get: function () { return js.LogtoError; }
|
|
264
|
+
});
|
|
265
|
+
Object.defineProperty(exports, 'LogtoRequestError', {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
get: function () { return js.LogtoRequestError; }
|
|
268
|
+
});
|
|
269
|
+
Object.defineProperty(exports, 'OidcError', {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
get: function () { return js.OidcError; }
|
|
272
|
+
});
|
|
273
|
+
Object.defineProperty(exports, 'Prompt', {
|
|
274
|
+
enumerable: true,
|
|
275
|
+
get: function () { return js.Prompt; }
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, 'ReservedScope', {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function () { return js.ReservedScope; }
|
|
280
|
+
});
|
|
281
|
+
Object.defineProperty(exports, 'UserScope', {
|
|
282
|
+
enumerable: true,
|
|
283
|
+
get: function () { return js.UserScope; }
|
|
284
|
+
});
|
|
285
|
+
exports.LogtoClientError = errors.LogtoClientError;
|
|
286
|
+
exports.isLogtoAccessTokenMap = index.isLogtoAccessTokenMap;
|
|
287
|
+
exports.isLogtoSignInSessionItem = index.isLogtoSignInSessionItem;
|
|
288
|
+
exports.createRequester = requester.createRequester;
|
|
289
|
+
exports.default = LogtoClient;
|