@darkauth/client 0.2.1 → 1.4.3
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/dist/index.js +16 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -29,9 +29,19 @@ let cfg = {
|
|
|
29
29
|
};
|
|
30
30
|
const OBFUSCATION_KEY = "DarkAuth-Storage-Protection-2025";
|
|
31
31
|
const EMPTY_DRK = new Uint8Array(0);
|
|
32
|
+
const ID_TOKEN_KEY = "id_token";
|
|
32
33
|
export function setConfig(next) {
|
|
33
34
|
cfg = { ...cfg, ...next };
|
|
34
35
|
}
|
|
36
|
+
function setStoredIdToken(token) {
|
|
37
|
+
localStorage.setItem(ID_TOKEN_KEY, token);
|
|
38
|
+
}
|
|
39
|
+
function getStoredIdToken() {
|
|
40
|
+
return localStorage.getItem(ID_TOKEN_KEY);
|
|
41
|
+
}
|
|
42
|
+
function clearStoredIdToken() {
|
|
43
|
+
localStorage.removeItem(ID_TOKEN_KEY);
|
|
44
|
+
}
|
|
35
45
|
function bytesToBase64Url(bytes) {
|
|
36
46
|
let s = "";
|
|
37
47
|
for (const b of bytes)
|
|
@@ -158,7 +168,7 @@ export async function handleCallback() {
|
|
|
158
168
|
history.replaceState(null, "", location.origin + location.pathname);
|
|
159
169
|
}
|
|
160
170
|
catch { }
|
|
161
|
-
|
|
171
|
+
setStoredIdToken(idToken);
|
|
162
172
|
localStorage.removeItem("drk_protected");
|
|
163
173
|
if (refreshToken)
|
|
164
174
|
localStorage.setItem("refresh_token", refreshToken);
|
|
@@ -182,7 +192,7 @@ export async function handleCallback() {
|
|
|
182
192
|
history.replaceState(null, "", location.origin + location.pathname);
|
|
183
193
|
}
|
|
184
194
|
catch { }
|
|
185
|
-
|
|
195
|
+
setStoredIdToken(idToken);
|
|
186
196
|
const obfuscatedDrk = obfuscateKey(drk);
|
|
187
197
|
localStorage.setItem("drk_protected", bytesToBase64Url(obfuscatedDrk));
|
|
188
198
|
if (refreshToken)
|
|
@@ -190,7 +200,7 @@ export async function handleCallback() {
|
|
|
190
200
|
return { idToken, drk, refreshToken };
|
|
191
201
|
}
|
|
192
202
|
export function getStoredSession() {
|
|
193
|
-
const idToken =
|
|
203
|
+
const idToken = getStoredIdToken();
|
|
194
204
|
const obfuscatedDrkBase64 = localStorage.getItem("drk_protected");
|
|
195
205
|
if (!idToken)
|
|
196
206
|
return null;
|
|
@@ -231,7 +241,7 @@ export async function refreshSession() {
|
|
|
231
241
|
const tokenResponse = await response.json();
|
|
232
242
|
const idToken = tokenResponse.id_token;
|
|
233
243
|
const newRefreshToken = tokenResponse.refresh_token;
|
|
234
|
-
|
|
244
|
+
setStoredIdToken(idToken);
|
|
235
245
|
if (newRefreshToken)
|
|
236
246
|
localStorage.setItem("refresh_token", newRefreshToken);
|
|
237
247
|
const obfuscatedDrkBase64 = localStorage.getItem("drk_protected");
|
|
@@ -242,14 +252,14 @@ export async function refreshSession() {
|
|
|
242
252
|
return { idToken, drk, refreshToken: newRefreshToken || refreshToken };
|
|
243
253
|
}
|
|
244
254
|
export function logout() {
|
|
245
|
-
|
|
255
|
+
clearStoredIdToken();
|
|
246
256
|
localStorage.removeItem("drk_protected");
|
|
247
257
|
sessionStorage.removeItem("zk_eph_priv_jwk");
|
|
248
258
|
sessionStorage.removeItem("pkce_verifier");
|
|
249
259
|
localStorage.removeItem("refresh_token");
|
|
250
260
|
}
|
|
251
261
|
export function getCurrentUser() {
|
|
252
|
-
const idToken =
|
|
262
|
+
const idToken = getStoredIdToken();
|
|
253
263
|
if (!idToken)
|
|
254
264
|
return null;
|
|
255
265
|
return parseJwt(idToken);
|