@mathismeadows/roamer-device-auth 1.5.0 → 1.5.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/package.json +1 -1
- package/roamer-device-auth.mjs +35 -4
package/package.json
CHANGED
package/roamer-device-auth.mjs
CHANGED
|
@@ -197,8 +197,20 @@ async function listKnownClientSlugs() {
|
|
|
197
197
|
for (const entry of entries) {
|
|
198
198
|
// Safe to split on "__" without ambiguity: neither a client slug (clientSlugFromInitializeLine)
|
|
199
199
|
// nor an identity key (identityKeyFromTokens) can contain an underscore post-sanitization.
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
200
|
+
const withIdentity = entry.match(/^roamer_(?:tokens|loopback_tokens)__([^_]+)__/);
|
|
201
|
+
if (withIdentity) {
|
|
202
|
+
slugs.add(withIdentity[1]);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
// BUG (found live 2026-09-08, caused a real cross-session logout): a slug that has never
|
|
206
|
+
// reconnected since AUTH-54 shipped only has the pre-AUTH-54 legacy file — no identity
|
|
207
|
+
// segment at all — and was invisible here. login/logout's own "if status lists exactly one
|
|
208
|
+
// slug, there's no ambiguity" reasoning then wrongly treated a real, actively-used client as
|
|
209
|
+
// nonexistent, silently acting on a *different* session's slug instead because it was the
|
|
210
|
+
// only one that happened to already be migrated. A legacy-only slug must still count as a
|
|
211
|
+
// real, known candidate even though it has no identity cached under the new scheme yet.
|
|
212
|
+
const legacy = entry.match(/^roamer_(?:tokens|loopback_tokens)__([^_]+)\.json$/);
|
|
213
|
+
if (legacy) slugs.add(legacy[1]);
|
|
202
214
|
}
|
|
203
215
|
return [...slugs].sort();
|
|
204
216
|
}
|
|
@@ -538,7 +550,22 @@ async function doGetValidTokens(clientSlug, forceRefresh, forceFreshLogin = fals
|
|
|
538
550
|
const active = forceFreshLogin ? null : await readActiveIdentity(clientSlug);
|
|
539
551
|
const identityKey = active?.identityKey ?? null;
|
|
540
552
|
|
|
541
|
-
|
|
553
|
+
// BUG (found live, same session, immediately post-1.5.0-publish): identityKey being null
|
|
554
|
+
// here is ambiguous between "no active identity has ever been established" (must never read
|
|
555
|
+
// any file — force a fresh sign-in) and "explicitly asked for the identity-less cache" (only
|
|
556
|
+
// ever true from a 2-arg test call). cacheFilePath maps a null identityKey to the exact same
|
|
557
|
+
// filename AUTH-54 shipped alongside — the pre-AUTH-54 file every already-authenticated
|
|
558
|
+
// client already had on disk. Without this guard, a machine upgrading straight from a
|
|
559
|
+
// pre-AUTH-54 version silently keeps reusing that old file forever (a real "reused existing
|
|
560
|
+
// creds" notification a user hit immediately after this shipped) and never establishes an
|
|
561
|
+
// active-identity pointer at all — reproducing the exact silent-stale-identity bug AUTH-54
|
|
562
|
+
// exists to fix, and permanently hiding that identity from login/logout/status, which only
|
|
563
|
+
// ever look at the new (client, identity)-keyed files. noActiveIdentity forces the same
|
|
564
|
+
// fresh-sign-in path a genuinely first-ever run takes, which is what self-heals into a real
|
|
565
|
+
// active pointer + a new-format file — see the fresh-sign-in branch below.
|
|
566
|
+
const noActiveIdentity = !forceFreshLogin && !active;
|
|
567
|
+
|
|
568
|
+
let tokens = forceRefresh || forceFreshLogin || noActiveIdentity ? null : await readCachedTokens(clientSlug, identityKey);
|
|
542
569
|
|
|
543
570
|
if (!forceRefresh && !forceFreshLogin && tokens?.access_token && !expiresSoon(tokens)) {
|
|
544
571
|
return { tokens, reusedSilently: true, identityKey, label: active?.label };
|
|
@@ -700,8 +727,12 @@ async function doGetValidTokensLoopback(clientSlug, forceRefresh, forceFreshLogi
|
|
|
700
727
|
|
|
701
728
|
const active = forceFreshLogin ? null : await readActiveIdentity(clientSlug);
|
|
702
729
|
const identityKey = active?.identityKey ?? null;
|
|
730
|
+
// See doGetValidTokens's identical guard above for why this is required, not optional: a
|
|
731
|
+
// null identityKey here would otherwise silently resolve to the exact pre-AUTH-54 filename.
|
|
732
|
+
const noActiveIdentity = !forceFreshLogin && !active;
|
|
703
733
|
|
|
704
|
-
let tokens =
|
|
734
|
+
let tokens =
|
|
735
|
+
forceRefresh || forceFreshLogin || noActiveIdentity ? null : await readLoopbackTokens(clientSlug, issuerUrl, identityKey);
|
|
705
736
|
|
|
706
737
|
if (!forceRefresh && !forceFreshLogin && tokens?.access_token && !expiresSoon(tokens)) {
|
|
707
738
|
return { tokens, reusedSilently: true, identityKey, label: active?.label };
|