@trimble-oss/trimble-id-react 0.1.1 → 1.0.0-rc.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/README.md +9 -15
- package/dist/TIDClient/TIDClient.d.ts +0 -19
- package/dist/TIDClient/index.d.ts +0 -2
- package/dist/TIDClient/interfaces.d.ts +1 -42
- package/dist/TIDClient/storage/cache-storage/CacheManager.d.ts +1 -34
- package/dist/TIDProvider/TIDProvider.d.ts +1 -9
- package/dist/index.d.ts +0 -1
- package/dist/trimble-id-react.es.js +147 -378
- package/dist/trimble-id-react.umd.js +1 -1
- package/package.json +2 -2
- package/dist/TIDClient/storage/cache-storage/CacheKey.d.ts +0 -46
- package/dist/TIDClient/storage/cache-storage/LocalStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/SessionStorageCache.d.ts +0 -67
- package/dist/TIDClient/storage/cache-storage/constants.d.ts +0 -15
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var
|
|
2
|
-
var B = (i, e, t) => e in i ?
|
|
3
|
-
var
|
|
4
|
-
import { OpenIdEndpointProvider as
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
import { createContext as q, useContext as
|
|
8
|
-
import { jsx as
|
|
9
|
-
class
|
|
1
|
+
var F = Object.defineProperty;
|
|
2
|
+
var B = (i, e, t) => e in i ? F(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var c = (i, e, t) => (B(i, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { OpenIdEndpointProvider as $, AuthorizationCodeGrantTokenProvider as R, AnalyticsHttpClient as H, BearerTokenHttpClientProvider as Q } from "@trimble-oss/trimble-id";
|
|
5
|
+
import * as w from "es-cookie";
|
|
6
|
+
import J from "jwt-decode";
|
|
7
|
+
import { createContext as q, useContext as L, useState as z, useReducer as X, useRef as Y, useMemo as M, useEffect as D, useCallback as y } from "react";
|
|
8
|
+
import { jsx as K, Fragment as Z } from "react/jsx-runtime";
|
|
9
|
+
class j {
|
|
10
10
|
constructor() {
|
|
11
11
|
/**
|
|
12
12
|
* This function generate a encapsulation function to store
|
|
@@ -15,7 +15,7 @@ class ie {
|
|
|
15
15
|
* @see {https://medium.com/javascript-scene/encapsulation-in-javascript-26be60e325b4} Encapsulation
|
|
16
16
|
* @return {CacheStorage} Key for the token
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
c(this, "generateCache", function() {
|
|
19
19
|
const e = {
|
|
20
20
|
token: void 0,
|
|
21
21
|
user: void 0
|
|
@@ -62,229 +62,14 @@ class ie {
|
|
|
62
62
|
}());
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
class
|
|
66
|
-
|
|
67
|
-
* Initialized configuration to store information into local storage
|
|
68
|
-
* @param {LocalStorageCacheOptions} options - Configuration for caching in localstorage
|
|
69
|
-
*/
|
|
70
|
-
constructor(e) {
|
|
71
|
-
/**
|
|
72
|
-
* Local storage from the browser
|
|
73
|
-
* @type {Storage}
|
|
74
|
-
*/
|
|
75
|
-
a(this, "localStorage");
|
|
76
|
-
/**
|
|
77
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
78
|
-
* @type {CacheKey}
|
|
79
|
-
*/
|
|
80
|
-
a(this, "cacheKey");
|
|
81
|
-
this.localStorage = window.localStorage, this.cacheKey = e.cacheKey;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get token store in localstorage
|
|
85
|
-
* @return {Promise<TIDAuthToken | undefined>} - Token store in localstorage
|
|
86
|
-
*/
|
|
87
|
-
async getToken() {
|
|
88
|
-
const e = this.getAuthKey(), t = localStorage.getItem(e);
|
|
89
|
-
return t ? JSON.parse(t) : void 0;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get user store in localstorage
|
|
93
|
-
* @return {Promise<TIDUser | undefined>} - User store in localstorage
|
|
94
|
-
*/
|
|
95
|
-
async getUser() {
|
|
96
|
-
const e = this.getUserKey(), t = localStorage.getItem(e);
|
|
97
|
-
return t ? JSON.parse(t) : void 0;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Store token in localstorage
|
|
101
|
-
* @param {TIDAuthToken} token - Token that you want to store in localstorage
|
|
102
|
-
* @return {Promise<void>} Empty promise
|
|
103
|
-
*/
|
|
104
|
-
async storeToken(e) {
|
|
105
|
-
const t = this.getAuthKey(), s = JSON.stringify(e);
|
|
106
|
-
localStorage.setItem(t, s);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Store user in cache
|
|
110
|
-
* @param {TIDUser} user - User that you want to store in localstorage
|
|
111
|
-
* @return {Promise<void>} Empty promise
|
|
112
|
-
*/
|
|
113
|
-
async storeUser(e) {
|
|
114
|
-
const t = this.getUserKey(), s = JSON.stringify(e);
|
|
115
|
-
localStorage.setItem(t, s);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Get the full key from the cachekey for the user
|
|
119
|
-
* @return {string} - Full key to get the token from the localstorage
|
|
120
|
-
*/
|
|
121
|
-
getUserKey() {
|
|
122
|
-
return this.cacheKey.getUserKey();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get the full key from the cachekey for the token
|
|
126
|
-
* @return {string} - Full key to get the token from the localstorage
|
|
127
|
-
*/
|
|
128
|
-
getAuthKey() {
|
|
129
|
-
return this.cacheKey.getAuthKey();
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* The clear the cache from the localstorage
|
|
133
|
-
* @return {Promise<void>} Empty promise
|
|
134
|
-
*/
|
|
135
|
-
clear() {
|
|
136
|
-
return this.localStorage.removeItem(this.getAuthKey()), this.localStorage.removeItem(this.getUserKey()), Promise.resolve(void 0);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const T = "@TID", re = `${T}_AUTH_KEY`, ne = `${T}_USER_KEY`;
|
|
140
|
-
class oe {
|
|
141
|
-
/**
|
|
142
|
-
* Initialized the cache key
|
|
143
|
-
* @param {CacheKeyOptions} cacheKeyOptions - Cache key options to edit the default values
|
|
144
|
-
*/
|
|
145
|
-
constructor(e) {
|
|
146
|
-
/**
|
|
147
|
-
* Client id of the application created in trimble developer console
|
|
148
|
-
* @type {string}
|
|
149
|
-
*/
|
|
150
|
-
a(this, "clientId");
|
|
151
|
-
/**
|
|
152
|
-
* Prefix value of the key, by default the prefix is based on the constant PREFIX_KEY
|
|
153
|
-
* @type {string}
|
|
154
|
-
*/
|
|
155
|
-
a(this, "prefix", T);
|
|
156
|
-
/**
|
|
157
|
-
* Suffix value use it to generate the key to store and retrieve the token, by default the prefix is based on the constant AUTH_KEY
|
|
158
|
-
* @type {string}
|
|
159
|
-
*/
|
|
160
|
-
a(this, "authSuffix", re);
|
|
161
|
-
/**
|
|
162
|
-
* Suffix value use it to generate the key to store and retrieve the user, by default the prefix is based on the constant USER_KEY
|
|
163
|
-
* @type {string}
|
|
164
|
-
*/
|
|
165
|
-
a(this, "userSuffix", ne);
|
|
166
|
-
this.clientId = e.client_id;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Get key to store/retrieve user
|
|
170
|
-
* @return {string} Key for the user
|
|
171
|
-
*/
|
|
172
|
-
getUserKey() {
|
|
173
|
-
return `${this.prefix}_${this.userSuffix}_${this.clientId}`;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get key to store/retrieve token
|
|
177
|
-
* @return {string} Key for the token
|
|
178
|
-
*/
|
|
179
|
-
getAuthKey() {
|
|
180
|
-
return `${this.prefix}_${this.authSuffix}_${this.clientId}`;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
class ae {
|
|
184
|
-
/**
|
|
185
|
-
* Initialized configuration to store information into session storage
|
|
186
|
-
* @param {SessionStorageCacheOptions} options - Configuration for caching in session storage
|
|
187
|
-
*/
|
|
188
|
-
constructor(e) {
|
|
189
|
-
/**
|
|
190
|
-
* Session storage from the browser
|
|
191
|
-
* @type {Storage}
|
|
192
|
-
*/
|
|
193
|
-
a(this, "sessionStorage");
|
|
194
|
-
/**
|
|
195
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
196
|
-
* @type {CacheKey}
|
|
197
|
-
*/
|
|
198
|
-
a(this, "cacheKey");
|
|
199
|
-
this.sessionStorage = window.sessionStorage, this.cacheKey = e.cacheKey;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Get token store in session storage
|
|
203
|
-
* @return {Promise<TIDAuthToken | undefined>} - Token store in session storage
|
|
204
|
-
*/
|
|
205
|
-
async getToken() {
|
|
206
|
-
const e = this.getAuthKey(), t = sessionStorage.getItem(e);
|
|
207
|
-
return t ? JSON.parse(t) : void 0;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Get user store in session storage
|
|
211
|
-
* @return {Promise<TIDUser | undefined>} - User store in session storage
|
|
212
|
-
*/
|
|
213
|
-
async getUser() {
|
|
214
|
-
const e = this.getUserKey(), t = sessionStorage.getItem(e);
|
|
215
|
-
return t ? JSON.parse(t) : void 0;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Store token in session storage
|
|
219
|
-
* @param {TIDAuthToken} authToken - Token that you want to store in session storage
|
|
220
|
-
* @return {Promise<void>} Empty promise
|
|
221
|
-
*/
|
|
222
|
-
async storeToken(e) {
|
|
223
|
-
const t = this.getAuthKey(), s = JSON.stringify(e);
|
|
224
|
-
sessionStorage.setItem(t, s);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Store user in cache
|
|
228
|
-
* @param {TIDUser} user - User that you want to store in session storage
|
|
229
|
-
* @return {Promise<void>} Empty promise
|
|
230
|
-
*/
|
|
231
|
-
async storeUser(e) {
|
|
232
|
-
const t = this.getUserKey(), s = JSON.stringify(e);
|
|
233
|
-
sessionStorage.setItem(t, s);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Get the full key from the cachekey for the user
|
|
237
|
-
* @return {string} - Full key to get the token from the session storage
|
|
238
|
-
*/
|
|
239
|
-
getUserKey() {
|
|
240
|
-
return this.cacheKey.getUserKey();
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Get the full key from the cachekey for the token
|
|
244
|
-
* @return {string} - Full key to get the token from the session storage
|
|
245
|
-
*/
|
|
246
|
-
getAuthKey() {
|
|
247
|
-
return this.cacheKey.getAuthKey();
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* The clear the cache from the session storage
|
|
251
|
-
* @return {Promise<void>} Empty promise
|
|
252
|
-
*/
|
|
253
|
-
clear() {
|
|
254
|
-
return this.sessionStorage.removeItem(this.getAuthKey()), this.sessionStorage.removeItem(this.getUserKey()), Promise.resolve(void 0);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
class ce {
|
|
258
|
-
/**
|
|
259
|
-
* Create a cache manager to extract or save the user, and token
|
|
260
|
-
* @param {CacheManagerOptions} options - Configuration for the managing the caching
|
|
261
|
-
*/
|
|
262
|
-
constructor(e) {
|
|
263
|
-
/**
|
|
264
|
-
* Type persistent you want the user and token to be store
|
|
265
|
-
* in-memory - This one will only persist will the user stays in the page
|
|
266
|
-
* localStorage - This persistent doesn't have expiration date
|
|
267
|
-
* sessionStorage - This one is cleared when the page session ends
|
|
268
|
-
* @type {PersistentStore}
|
|
269
|
-
*/
|
|
270
|
-
a(this, "persistentStore");
|
|
65
|
+
class ee {
|
|
66
|
+
constructor() {
|
|
271
67
|
/**
|
|
272
68
|
* Cache option selected
|
|
273
69
|
* @type {CacheStorage}
|
|
274
70
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
* The cache key represents the keys for storing and retrieving user and token from auth
|
|
278
|
-
* @type {CacheKey}
|
|
279
|
-
*/
|
|
280
|
-
a(this, "cacheKey");
|
|
281
|
-
this.persistentStore = e.persistentStore, this.cacheKey = new oe({
|
|
282
|
-
client_id: e.clientId
|
|
283
|
-
}), this.persistentStore === "localStorage" ? this.cacheStorage = new se({
|
|
284
|
-
cacheKey: this.cacheKey
|
|
285
|
-
}) : this.persistentStore === "sessionStorage" ? this.cacheStorage = new ae({
|
|
286
|
-
cacheKey: this.cacheKey
|
|
287
|
-
}) : this.cacheStorage = new ie().generateCache;
|
|
71
|
+
c(this, "cacheStorage");
|
|
72
|
+
this.cacheStorage = new j().generateCache;
|
|
288
73
|
}
|
|
289
74
|
/**
|
|
290
75
|
* Store token in cache
|
|
@@ -324,7 +109,7 @@ class ce {
|
|
|
324
109
|
await this.cacheStorage.clear();
|
|
325
110
|
}
|
|
326
111
|
}
|
|
327
|
-
const x = 5 * 6e4,
|
|
112
|
+
const x = 5 * 6e4, te = ["code", "state"], A = (i) => i.split("?")[0], ie = (i) => i.split("?")[1], b = (i) => {
|
|
328
113
|
let e = i;
|
|
329
114
|
if (!i.startsWith("?"))
|
|
330
115
|
try {
|
|
@@ -332,34 +117,33 @@ const x = 5 * 6e4, le = ["code", "state"], O = (i) => i.split("?")[0], he = (i)
|
|
|
332
117
|
} catch {
|
|
333
118
|
}
|
|
334
119
|
return new URLSearchParams(e);
|
|
335
|
-
},
|
|
120
|
+
}, ne = (i = window.location.href, e) => {
|
|
336
121
|
if (e != null) {
|
|
337
|
-
const
|
|
338
|
-
if (
|
|
122
|
+
const n = A(e), r = A(i ?? "");
|
|
123
|
+
if (n !== r)
|
|
339
124
|
return !1;
|
|
340
125
|
}
|
|
341
|
-
const t =
|
|
342
|
-
for (const
|
|
343
|
-
if (!t.has(
|
|
126
|
+
const t = b(i);
|
|
127
|
+
for (const n of te)
|
|
128
|
+
if (!t.has(n))
|
|
344
129
|
return !1;
|
|
345
130
|
return !0;
|
|
346
|
-
},
|
|
131
|
+
}, re = (i) => ({
|
|
347
132
|
id: i.sub,
|
|
348
133
|
name: `${i.given_name} ${i.family_name}`,
|
|
349
134
|
given_name: i.given_name,
|
|
350
135
|
family_name: i.family_name,
|
|
351
136
|
picture: i.picture,
|
|
352
137
|
email: i.email,
|
|
353
|
-
email_verified: i.email_verified
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
class ye {
|
|
138
|
+
email_verified: i.email_verified
|
|
139
|
+
}), se = "@TID_COOKIE";
|
|
140
|
+
class oe {
|
|
357
141
|
/**
|
|
358
142
|
* Retrieve a cookie from the browser
|
|
359
143
|
* @param {string} key - Key to retrieve the cookies
|
|
360
144
|
*/
|
|
361
145
|
get(e) {
|
|
362
|
-
const t =
|
|
146
|
+
const t = w.get(e);
|
|
363
147
|
if (t == null)
|
|
364
148
|
throw new Error("Cookie not found");
|
|
365
149
|
return JSON.parse(t);
|
|
@@ -374,12 +158,12 @@ class ye {
|
|
|
374
158
|
* @example Save cookies with a custom domain
|
|
375
159
|
* cookiesStorage.set('key',{data:{...}},{domain:'https://example.com/subpath'})
|
|
376
160
|
*/
|
|
377
|
-
set(e, t,
|
|
161
|
+
set(e, t, n) {
|
|
378
162
|
let r = {};
|
|
379
163
|
window.location.protocol === "https:" && (r = {
|
|
380
164
|
secure: !0,
|
|
381
165
|
sameSite: "none"
|
|
382
|
-
}),
|
|
166
|
+
}), n != null && n.expires && (r.expires = n.expires), n != null && n.domain && (r.domain = n.domain), w.set(e, JSON.stringify(t), r);
|
|
383
167
|
}
|
|
384
168
|
/**
|
|
385
169
|
* Remove a cookie from the browser
|
|
@@ -391,11 +175,11 @@ class ye {
|
|
|
391
175
|
* cookiesStorage.remove('key',{domain:'https://example.com/subpath'})
|
|
392
176
|
*/
|
|
393
177
|
remove(e, t) {
|
|
394
|
-
const
|
|
395
|
-
t != null && t.domain && (
|
|
178
|
+
const n = {};
|
|
179
|
+
t != null && t.domain && (n.domain = t.domain), w.remove(e, n);
|
|
396
180
|
}
|
|
397
181
|
}
|
|
398
|
-
class
|
|
182
|
+
class ae {
|
|
399
183
|
/**
|
|
400
184
|
* Create a cookies manager to extract or save cookies in the browser
|
|
401
185
|
* @param {CookiesManagerOptions} options - Configuration for the managing the cookies
|
|
@@ -405,13 +189,13 @@ class fe {
|
|
|
405
189
|
* Cookie full key to store and retrieve the information from cookies
|
|
406
190
|
* @type {string}
|
|
407
191
|
*/
|
|
408
|
-
|
|
192
|
+
c(this, "cookieKey");
|
|
409
193
|
/**
|
|
410
194
|
* Cookie storage. This object contain all functions necessary to retrieve and store tokens using cookies
|
|
411
195
|
* @type {CookiesStorage}
|
|
412
196
|
*/
|
|
413
|
-
|
|
414
|
-
this.cookieKey = `${
|
|
197
|
+
c(this, "cookiesStorage");
|
|
198
|
+
this.cookieKey = `${se}.${e.clientId}`, this.cookiesStorage = new oe();
|
|
415
199
|
}
|
|
416
200
|
/**
|
|
417
201
|
* Store cookies in the browser
|
|
@@ -440,22 +224,20 @@ class fe {
|
|
|
440
224
|
this.cookiesStorage.remove(this.cookieKey);
|
|
441
225
|
}
|
|
442
226
|
}
|
|
443
|
-
class
|
|
227
|
+
class U extends Error {
|
|
444
228
|
}
|
|
445
|
-
class
|
|
229
|
+
class O extends Error {
|
|
446
230
|
}
|
|
447
|
-
class
|
|
231
|
+
class ce extends Error {
|
|
448
232
|
}
|
|
449
|
-
const d = "@trimble-oss/trimble-id-react",
|
|
233
|
+
const d = "@trimble-oss/trimble-id-react", h = "1.0.0-rc.2", le = {
|
|
450
234
|
configurationEndpoint: "",
|
|
451
235
|
clientId: "",
|
|
452
236
|
redirectUrl: "",
|
|
453
237
|
logoutRedirectUrl: "",
|
|
454
238
|
scopes: []
|
|
455
|
-
}, Se = {
|
|
456
|
-
persistentStore: "in-memory"
|
|
457
239
|
};
|
|
458
|
-
class
|
|
240
|
+
class de {
|
|
459
241
|
/**
|
|
460
242
|
* Create a TID client to handle manage all user authentication functions and information
|
|
461
243
|
* @param {CacheManagerOptions} props - TID client configuration
|
|
@@ -465,50 +247,47 @@ class pe {
|
|
|
465
247
|
* Token provider SDK. This object handles all necessary communication with TID
|
|
466
248
|
* @type {AuthorizationCodeGrantTokenProvider}
|
|
467
249
|
*/
|
|
468
|
-
|
|
250
|
+
c(this, "tokenProvider");
|
|
469
251
|
/**
|
|
470
252
|
* This object manage all caching, and all configurations necessary
|
|
471
253
|
* @type {CacheManager}
|
|
472
254
|
*/
|
|
473
|
-
|
|
255
|
+
c(this, "cacheManager");
|
|
474
256
|
/**
|
|
475
257
|
* This object manage all cookies administration, and all configurations necessary
|
|
476
258
|
* @type {CookiesManager}
|
|
477
259
|
*/
|
|
478
|
-
|
|
260
|
+
c(this, "cookiesManager");
|
|
479
261
|
/**
|
|
480
262
|
* Client id of the application created in trimble developer console
|
|
481
263
|
* @type {string}
|
|
482
264
|
*/
|
|
483
|
-
|
|
265
|
+
c(this, "clientId");
|
|
484
266
|
/**
|
|
485
267
|
* Callback url to redirect the user after the authentication is successful
|
|
486
268
|
* @type {string}
|
|
487
269
|
*/
|
|
488
|
-
|
|
270
|
+
c(this, "redirectUrl");
|
|
489
271
|
/**
|
|
490
272
|
* AnalyticsHttpClient for sending events
|
|
491
273
|
* @type {AnalyticsHttpClient}
|
|
492
274
|
*/
|
|
493
|
-
|
|
494
|
-
const { config: t =
|
|
275
|
+
c(this, "analyticshttpclient");
|
|
276
|
+
const { config: t = le } = e;
|
|
495
277
|
if (this.redirectUrl = t.redirectUrl, t.configurationEndpoint == null || t.configurationEndpoint == "")
|
|
496
278
|
throw new Error("Configuration endpoint not defined");
|
|
497
279
|
if (t.clientId == null || t.clientId == "")
|
|
498
280
|
throw new Error("Consumer key is not defined");
|
|
499
|
-
this.cookiesManager = new
|
|
281
|
+
this.cookiesManager = new ae({
|
|
500
282
|
clientId: t.clientId
|
|
501
283
|
});
|
|
502
|
-
const
|
|
503
|
-
let
|
|
504
|
-
|
|
284
|
+
const n = this.cookiesManager.get(), r = new $(t.configurationEndpoint);
|
|
285
|
+
let a = new R(
|
|
286
|
+
r,
|
|
505
287
|
t.clientId,
|
|
506
288
|
t.redirectUrl
|
|
507
289
|
).WithScopes(t.scopes);
|
|
508
|
-
t.logoutRedirectUrl && (
|
|
509
|
-
clientId: t.clientId,
|
|
510
|
-
persistentStore: s.persistentStore
|
|
511
|
-
}), this.clientId = t.clientId, this.analyticshttpclient = z, this.analyticshttpclient.sendInitEvent("TIDClient", this.clientId, d, u);
|
|
290
|
+
t.logoutRedirectUrl && (a = a.WithLogoutRedirect(t.logoutRedirectUrl)), (n == null ? void 0 : n.code_verifier) != null && (a = a.WithProofKeyForCodeExchange(n.code_verifier)), this.tokenProvider = a, this.cacheManager = new ee(), this.clientId = t.clientId, this.analyticshttpclient = H, this.analyticshttpclient.sendInitEvent("TIDClient", this.clientId, d, h);
|
|
512
291
|
}
|
|
513
292
|
/**
|
|
514
293
|
* Redirect the user to TID using the browser
|
|
@@ -523,9 +302,9 @@ class pe {
|
|
|
523
302
|
* // So it can be handled by the developer
|
|
524
303
|
*/
|
|
525
304
|
async loginWithRedirect(e) {
|
|
526
|
-
this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name, this.clientId, d,
|
|
527
|
-
const { onRedirect: t } = e || {},
|
|
528
|
-
this.cookiesManager.save({ code_verifier:
|
|
305
|
+
this.analyticshttpclient.sendMethodEvent(this.loginWithRedirect.name, this.clientId, d, h);
|
|
306
|
+
const { onRedirect: t } = e || {}, n = R.GenerateCodeVerifier();
|
|
307
|
+
this.cookiesManager.save({ code_verifier: n }), this.tokenProvider = this.tokenProvider.WithProofKeyForCodeExchange(n);
|
|
529
308
|
const r = await this.tokenProvider.GetOAuthRedirect("state");
|
|
530
309
|
t != null ? t(r) : window.location.assign(r);
|
|
531
310
|
}
|
|
@@ -544,10 +323,10 @@ class pe {
|
|
|
544
323
|
async handleCallback(e = window.location.href) {
|
|
545
324
|
const t = this.cookiesManager.get();
|
|
546
325
|
if (t == null || (t == null ? void 0 : t.code_verifier) == null)
|
|
547
|
-
throw new
|
|
548
|
-
const
|
|
549
|
-
return await this.tokenProvider.ValidateQuery(
|
|
550
|
-
authState:
|
|
326
|
+
throw new ce("Code verifier not available");
|
|
327
|
+
const n = ie(e), r = b(e), a = r.get("identity_provider") ?? "", g = r.get("state") ?? "";
|
|
328
|
+
return await this.tokenProvider.ValidateQuery(n), await this.generateToken(a), {
|
|
329
|
+
authState: g
|
|
551
330
|
};
|
|
552
331
|
}
|
|
553
332
|
/**
|
|
@@ -556,21 +335,21 @@ class pe {
|
|
|
556
335
|
* @return {Promise<void>} Empty promise
|
|
557
336
|
*/
|
|
558
337
|
async generateToken(e) {
|
|
559
|
-
var
|
|
560
|
-
const t = await this.tokenProvider.RetrieveToken(),
|
|
338
|
+
var s, f;
|
|
339
|
+
const t = await this.tokenProvider.RetrieveToken(), n = await this.tokenProvider.RetrieveRefreshToken(), r = await this.tokenProvider.RetrieveIdToken(), a = await this.tokenProvider.RetrieveTokenExpiry(), k = new Date(a).getTime(), v = (f = (s = this.tokenProvider) == null ? void 0 : s._scopes) == null ? void 0 : f.join(" ");
|
|
561
340
|
await this.cacheManager.setToken({
|
|
562
|
-
scope:
|
|
341
|
+
scope: v,
|
|
563
342
|
state: "",
|
|
564
343
|
session_state: "",
|
|
565
344
|
identity_provider: e,
|
|
566
345
|
token_type: "bearer",
|
|
567
346
|
access_token: t,
|
|
568
|
-
refresh_token:
|
|
347
|
+
refresh_token: n,
|
|
569
348
|
id_token: r,
|
|
570
349
|
expires_at: k
|
|
571
350
|
});
|
|
572
|
-
const m =
|
|
573
|
-
await this.cacheManager.setUser(
|
|
351
|
+
const m = J(r), T = re(m);
|
|
352
|
+
await this.cacheManager.setUser(T), await this.reloadCodeVerifier();
|
|
574
353
|
}
|
|
575
354
|
async reloadCodeVerifier() {
|
|
576
355
|
const e = await this.tokenProvider.RetrieveCodeVerifier();
|
|
@@ -581,7 +360,7 @@ class pe {
|
|
|
581
360
|
* @return {Promise<TIDUser | undefined>} User in cache
|
|
582
361
|
*/
|
|
583
362
|
async getUser() {
|
|
584
|
-
return this.analyticshttpclient.sendMethodEvent(this.getUser.name, this.clientId, d,
|
|
363
|
+
return this.analyticshttpclient.sendMethodEvent(this.getUser.name, this.clientId, d, h), await this.cacheManager.getUser();
|
|
585
364
|
}
|
|
586
365
|
/**
|
|
587
366
|
* Gets the access token from cache. If the token already expired,
|
|
@@ -591,16 +370,16 @@ class pe {
|
|
|
591
370
|
* @throws {TokenExpiredException} Will throw an exception if the user token expired
|
|
592
371
|
*/
|
|
593
372
|
async getAccessTokenSilently() {
|
|
594
|
-
this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name, this.clientId, d,
|
|
373
|
+
this.analyticshttpclient.sendMethodEvent(this.getAccessTokenSilently.name, this.clientId, d, h);
|
|
595
374
|
let e = await this.cacheManager.getToken();
|
|
596
375
|
if (e == null)
|
|
597
|
-
throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name, "No token available", this.clientId, d,
|
|
376
|
+
throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name, "No token available", this.clientId, d, h), new O("No token available");
|
|
598
377
|
const t = new Date((/* @__PURE__ */ new Date()).getTime() + x);
|
|
599
378
|
if ((e == null ? void 0 : e.expires_at) == null || (e == null ? void 0 : e.expires_at) < t.getTime()) {
|
|
600
379
|
try {
|
|
601
380
|
await this.tokenProvider.RetrieveToken();
|
|
602
|
-
} catch (
|
|
603
|
-
throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name,
|
|
381
|
+
} catch (n) {
|
|
382
|
+
throw this.analyticshttpclient.sendExceptionEvent(this.getAccessTokenSilently.name, n.message, this.clientId, d, h), new U(n.message);
|
|
604
383
|
}
|
|
605
384
|
await this.generateToken((e == null ? void 0 : e.identity_provider) ?? ""), e = await this.cacheManager.getToken();
|
|
606
385
|
}
|
|
@@ -614,16 +393,16 @@ class pe {
|
|
|
614
393
|
* @throws {TokenExpiredException} Will throw an exception if the user token expired
|
|
615
394
|
*/
|
|
616
395
|
async getTokens() {
|
|
617
|
-
this.analyticshttpclient.sendMethodEvent(this.getTokens.name, this.clientId, d,
|
|
396
|
+
this.analyticshttpclient.sendMethodEvent(this.getTokens.name, this.clientId, d, h);
|
|
618
397
|
let e = await this.cacheManager.getToken();
|
|
619
398
|
if (e == null)
|
|
620
|
-
throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name, "No token available", this.clientId, d,
|
|
399
|
+
throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name, "No token available", this.clientId, d, h), new O("No token available");
|
|
621
400
|
const t = new Date((/* @__PURE__ */ new Date()).getTime() + x);
|
|
622
401
|
if ((e == null ? void 0 : e.expires_at) == null || (e == null ? void 0 : e.expires_at) < t.getTime()) {
|
|
623
402
|
try {
|
|
624
403
|
await this.tokenProvider.RetrieveToken();
|
|
625
|
-
} catch (
|
|
626
|
-
throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name,
|
|
404
|
+
} catch (n) {
|
|
405
|
+
throw this.analyticshttpclient.sendExceptionEvent(this.getTokens.name, n.message, this.clientId, d, h), new U(n.message);
|
|
627
406
|
}
|
|
628
407
|
await this.generateToken((e == null ? void 0 : e.identity_provider) ?? ""), e = await this.cacheManager.getToken();
|
|
629
408
|
}
|
|
@@ -646,13 +425,13 @@ class pe {
|
|
|
646
425
|
* // So it can be handled by the developer
|
|
647
426
|
*/
|
|
648
427
|
async logout(e) {
|
|
649
|
-
this.analyticshttpclient.sendMethodEvent(this.logout.name, this.clientId, d,
|
|
650
|
-
const { onRedirect: t, disabledAutoRedirect:
|
|
428
|
+
this.analyticshttpclient.sendMethodEvent(this.logout.name, this.clientId, d, h);
|
|
429
|
+
const { onRedirect: t, disabledAutoRedirect: n } = e || {};
|
|
651
430
|
this.cacheManager && await this.cacheManager.clear(), this.cookiesManager && this.cookiesManager.clear();
|
|
652
431
|
const r = await this.tokenProvider.GetOAuthLogoutRedirect("state");
|
|
653
432
|
if (t != null)
|
|
654
433
|
return t(r);
|
|
655
|
-
|
|
434
|
+
n || window.location.assign(r);
|
|
656
435
|
}
|
|
657
436
|
/**
|
|
658
437
|
* Check if the user still has a valid session
|
|
@@ -681,8 +460,8 @@ class pe {
|
|
|
681
460
|
const e = await this.cacheManager.getToken();
|
|
682
461
|
if (e == null)
|
|
683
462
|
return;
|
|
684
|
-
const t = e.access_token,
|
|
685
|
-
this.tokenProvider = this.tokenProvider.WithAccessToken(t,
|
|
463
|
+
const t = e.access_token, n = e.refresh_token || "", r = e.id_token, a = e.expires_at;
|
|
464
|
+
this.tokenProvider = this.tokenProvider.WithAccessToken(t, a).WithRefreshToken(n).WithIdToken(r);
|
|
686
465
|
}
|
|
687
466
|
/**
|
|
688
467
|
* Get a http bearer token client to use it for another SDK (Ex: Processing framework)
|
|
@@ -699,7 +478,7 @@ class pe {
|
|
|
699
478
|
return this.redirectUrl;
|
|
700
479
|
}
|
|
701
480
|
}
|
|
702
|
-
const
|
|
481
|
+
const E = q(null), W = () => L(E) ?? {}, he = (i, e) => {
|
|
703
482
|
switch (e.type) {
|
|
704
483
|
case "INIT":
|
|
705
484
|
return {
|
|
@@ -732,10 +511,10 @@ const v = q(null), $ = () => N(v) ?? {}, ve = (i, e) => {
|
|
|
732
511
|
error: e.error
|
|
733
512
|
};
|
|
734
513
|
}
|
|
735
|
-
},
|
|
514
|
+
}, ue = {
|
|
736
515
|
isLoading: !0,
|
|
737
516
|
isAuthenticated: !1
|
|
738
|
-
},
|
|
517
|
+
}, ge = (i) => {
|
|
739
518
|
if (i == null || Object.keys(i).length <= 0)
|
|
740
519
|
return !0;
|
|
741
520
|
const e = Object.keys(i);
|
|
@@ -743,124 +522,114 @@ const v = q(null), $ = () => N(v) ?? {}, ve = (i, e) => {
|
|
|
743
522
|
if (i[t] != null && i[t] !== "")
|
|
744
523
|
return !1;
|
|
745
524
|
return !0;
|
|
746
|
-
},
|
|
747
|
-
const e = D(i.config), t = D(i.persistentOptions);
|
|
748
|
-
return !e || !t;
|
|
749
|
-
}, we = (i) => {
|
|
525
|
+
}, ke = (i) => !ge(i.config), fe = (i) => {
|
|
750
526
|
const {
|
|
751
527
|
children: e,
|
|
752
528
|
configurationEndpoint: t,
|
|
753
|
-
clientId:
|
|
529
|
+
clientId: n,
|
|
754
530
|
redirectUrl: r,
|
|
755
|
-
logoutRedirectUrl:
|
|
756
|
-
scopes:
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
checkRedirectUrlMatch: m
|
|
531
|
+
logoutRedirectUrl: a,
|
|
532
|
+
scopes: g,
|
|
533
|
+
onRedirectCallback: k,
|
|
534
|
+
checkRedirectUrlMatch: v
|
|
760
535
|
} = i;
|
|
761
|
-
if (
|
|
536
|
+
if (L(E) != null)
|
|
762
537
|
throw new Error("TID Provider already defined");
|
|
763
|
-
const
|
|
538
|
+
const T = {
|
|
764
539
|
config: {
|
|
765
540
|
configurationEndpoint: t ?? "",
|
|
766
|
-
clientId:
|
|
541
|
+
clientId: n ?? "",
|
|
767
542
|
redirectUrl: r ?? "",
|
|
768
|
-
logoutRedirectUrl:
|
|
769
|
-
scopes:
|
|
770
|
-
},
|
|
771
|
-
persistentOptions: {
|
|
772
|
-
persistentStore: k ?? "in-memory"
|
|
543
|
+
logoutRedirectUrl: a ?? "",
|
|
544
|
+
scopes: g ?? [""]
|
|
773
545
|
}
|
|
774
|
-
}, [
|
|
775
|
-
() =>
|
|
776
|
-
[
|
|
546
|
+
}, [s] = z(i.tidClient ?? new de(T)), [f, u] = X(he, ue), p = Y(!1), N = M(
|
|
547
|
+
() => v ? s.getRedirectUrl() : void 0,
|
|
548
|
+
[v, s]
|
|
777
549
|
);
|
|
778
|
-
|
|
779
|
-
|
|
550
|
+
D(() => {
|
|
551
|
+
p.current || (i.tidClient != null && ke({
|
|
780
552
|
config: {
|
|
781
553
|
configurationEndpoint: t,
|
|
782
|
-
clientId:
|
|
554
|
+
clientId: n,
|
|
783
555
|
redirectUrl: r,
|
|
784
|
-
logoutRedirectUrl:
|
|
785
|
-
scopes:
|
|
786
|
-
},
|
|
787
|
-
persistentOptions: {
|
|
788
|
-
persistentStore: k
|
|
556
|
+
logoutRedirectUrl: a,
|
|
557
|
+
scopes: g
|
|
789
558
|
}
|
|
790
559
|
}) && console.warn(
|
|
791
560
|
"When TID client is pass as prop, any client configuration property sent directly to the TID Provider component will be ignored"
|
|
792
|
-
),
|
|
561
|
+
), p.current = !0, (async () => {
|
|
793
562
|
try {
|
|
794
563
|
let o;
|
|
795
|
-
if (
|
|
796
|
-
const { authState:
|
|
797
|
-
o = await
|
|
564
|
+
if (ne(void 0, N)) {
|
|
565
|
+
const { authState: l } = await s.handleCallback();
|
|
566
|
+
o = await s.getUser(), k != null && k(l);
|
|
798
567
|
} else
|
|
799
|
-
await
|
|
800
|
-
|
|
568
|
+
await s.loadUserSession(), o = await s.getUser();
|
|
569
|
+
u({ type: "INIT", user: o });
|
|
801
570
|
} catch (o) {
|
|
802
|
-
let
|
|
803
|
-
typeof o == "string" && (
|
|
571
|
+
let l = o;
|
|
572
|
+
typeof o == "string" && (l = new Error(o)), u({ type: "ERROR", error: l });
|
|
804
573
|
}
|
|
805
574
|
})());
|
|
806
|
-
}, [
|
|
807
|
-
const
|
|
808
|
-
const o = await
|
|
809
|
-
return
|
|
575
|
+
}, [s, k]);
|
|
576
|
+
const _ = y(async () => {
|
|
577
|
+
const o = await s.getAccessTokenSilently(), l = await s.getUser();
|
|
578
|
+
return u({
|
|
810
579
|
type: "GET_ACCESS_TOKEN_COMPLETE",
|
|
811
|
-
user:
|
|
580
|
+
user: l
|
|
812
581
|
}), o;
|
|
813
|
-
}, [
|
|
814
|
-
const o = await
|
|
815
|
-
return
|
|
582
|
+
}, [s]), C = y(async () => {
|
|
583
|
+
const o = await s.getTokens(), l = await s.getUser();
|
|
584
|
+
return u({
|
|
816
585
|
type: "GET_TOKENS_COMPLETE",
|
|
817
|
-
user:
|
|
586
|
+
user: l
|
|
818
587
|
}), o;
|
|
819
|
-
}, [
|
|
588
|
+
}, [s]), S = y(
|
|
820
589
|
async (o) => {
|
|
821
|
-
await
|
|
590
|
+
await s.loginWithRedirect(o);
|
|
822
591
|
},
|
|
823
|
-
[
|
|
824
|
-
),
|
|
592
|
+
[s]
|
|
593
|
+
), I = y(
|
|
825
594
|
async (o) => {
|
|
826
|
-
await
|
|
595
|
+
await s.logout(o), (o == null ? void 0 : o.disabledAutoRedirect) != null && o.disabledAutoRedirect && u({
|
|
827
596
|
type: "LOGOUT"
|
|
828
597
|
});
|
|
829
598
|
},
|
|
830
|
-
[
|
|
831
|
-
), P =
|
|
599
|
+
[s]
|
|
600
|
+
), P = y(
|
|
832
601
|
async (o) => {
|
|
833
|
-
const { authState:
|
|
834
|
-
return
|
|
602
|
+
const { authState: l } = await s.handleCallback(o), V = await s.getUser();
|
|
603
|
+
return u({
|
|
835
604
|
type: "HANDLE_CALLBACK_COMPLETE",
|
|
836
|
-
user:
|
|
605
|
+
user: V
|
|
837
606
|
}), {
|
|
838
|
-
authState:
|
|
607
|
+
authState: l
|
|
839
608
|
};
|
|
840
609
|
},
|
|
841
|
-
[
|
|
842
|
-
),
|
|
610
|
+
[s]
|
|
611
|
+
), G = M(
|
|
843
612
|
() => ({
|
|
844
|
-
...
|
|
845
|
-
getAccessTokenSilently:
|
|
846
|
-
getTokens:
|
|
847
|
-
loginWithRedirect:
|
|
613
|
+
...f,
|
|
614
|
+
getAccessTokenSilently: _,
|
|
615
|
+
getTokens: C,
|
|
616
|
+
loginWithRedirect: S,
|
|
848
617
|
handleCallback: P,
|
|
849
|
-
logout:
|
|
618
|
+
logout: I
|
|
850
619
|
}),
|
|
851
|
-
[
|
|
620
|
+
[f, _, C, S, P, I]
|
|
852
621
|
);
|
|
853
|
-
return /* @__PURE__ */
|
|
854
|
-
},
|
|
855
|
-
const { isAuthenticated: t, isLoading:
|
|
856
|
-
return
|
|
857
|
-
!
|
|
858
|
-
}, [
|
|
622
|
+
return /* @__PURE__ */ K(E.Provider, { value: G, children: e });
|
|
623
|
+
}, me = W, pe = fe, _e = ({ renderComponent: i, loader: e }) => {
|
|
624
|
+
const { isAuthenticated: t, isLoading: n, loginWithRedirect: r } = W();
|
|
625
|
+
return D(() => {
|
|
626
|
+
!n && !t && (async () => await r())();
|
|
627
|
+
}, [n, t, r]), t ? i : e || /* @__PURE__ */ K(Z, {});
|
|
859
628
|
};
|
|
860
629
|
export {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
630
|
+
_e as AuthenticationGuard,
|
|
631
|
+
de as TIDClient,
|
|
632
|
+
E as TIDContext,
|
|
633
|
+
pe as TIDProvider,
|
|
634
|
+
me as useAuth
|
|
866
635
|
};
|