@ccmsg/cli 0.2.6 → 0.2.7
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/src/auth/auth.ts +21 -1
package/package.json
CHANGED
package/src/auth/auth.ts
CHANGED
|
@@ -59,6 +59,19 @@ export const REFRESH_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
59
59
|
* short to be a second usable token. */
|
|
60
60
|
export const PREVIOUS_GRACE_MS = 60_000;
|
|
61
61
|
|
|
62
|
+
/** How much of an access token's life must be left for a rotation to keep it.
|
|
63
|
+
*
|
|
64
|
+
* A family has one access token and every page a person has open presents it,
|
|
65
|
+
* so minting a new one on each rotation would take the token out from under the
|
|
66
|
+
* pages that are already holding it. Rotation therefore keeps the standing
|
|
67
|
+
* access token while it has this much life left, and mints only when it is
|
|
68
|
+
* running out — the pages share one token and renew it together.
|
|
69
|
+
*
|
|
70
|
+
* Half, because it is the largest share that still leaves a full half of the
|
|
71
|
+
* token's life to notice the new value in: the window is what bounds how long a
|
|
72
|
+
* page may go on holding a token whose family has already moved on. */
|
|
73
|
+
export const ACCESS_KEEP_MS = ACCESS_TTL_MS / 2;
|
|
74
|
+
|
|
62
75
|
/** How many times a six-digit code may be got wrong before the registration URL
|
|
63
76
|
* is spent.
|
|
64
77
|
*
|
|
@@ -706,11 +719,18 @@ export class Auth {
|
|
|
706
719
|
return { sub: held.body.sub, access: held.body.access, refresh: held.body.refresh };
|
|
707
720
|
}
|
|
708
721
|
const at = this.#now();
|
|
722
|
+
// The refresh token rotates every time; the access token is the family's
|
|
723
|
+
// one token and is shared by every page the person has open, so it is kept
|
|
724
|
+
// until it is close enough to running out to be worth replacing.
|
|
725
|
+
const access =
|
|
726
|
+
held.body.access.expires_at - at >= ACCESS_KEEP_MS
|
|
727
|
+
? held.body.access
|
|
728
|
+
: { value: token(), expires_at: at + ACCESS_TTL_MS };
|
|
709
729
|
const rotated: TokenFamily = {
|
|
710
730
|
kind: "token_family",
|
|
711
731
|
sub: held.body.sub,
|
|
712
732
|
iss: this.deps.self,
|
|
713
|
-
access
|
|
733
|
+
access,
|
|
714
734
|
refresh: { value: token(), expires_at: at + REFRESH_TTL_MS },
|
|
715
735
|
previous_refresh: { value: held.body.refresh.value, expires_at: at + PREVIOUS_GRACE_MS },
|
|
716
736
|
// The value going out of service is remembered as a digest for as long as
|