Release 2.5.2
This commit is contained in:
+22
-1
@@ -246,12 +246,13 @@ function verifyRequestAuth(req) {
|
||||
return timingSafeEqualHex(expectedSignature, signature);
|
||||
}
|
||||
|
||||
function createPageFetchAuthScript(token) {
|
||||
function createPageFetchAuthScript(token, cookiePath) {
|
||||
const normalizedToken = String(token && typeof token === 'object' ? token.token : token || '').trim();
|
||||
if (!normalizedToken) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const normalizedCookiePath = String(cookiePath || '').trim();
|
||||
const pageAuthExpiresAt = token && typeof token === 'object' && Number.isFinite(Number(token.expiresAt))
|
||||
? Number(token.expiresAt)
|
||||
: null;
|
||||
@@ -262,6 +263,8 @@ function createPageFetchAuthScript(token) {
|
||||
' (function () {',
|
||||
' var pageAuthToken = ' + JSON.stringify(normalizedToken) + ';',
|
||||
' var pageAuthExpiresAt = ' + JSON.stringify(pageAuthExpiresAt) + ';',
|
||||
' var pageAuthCookiePath = ' + JSON.stringify(normalizedCookiePath) + ';',
|
||||
' var pageAuthCookieName = "pulse_page_auth";',
|
||||
' var pageAuthRenewalTimer = null;',
|
||||
' var pageAuthRenewalInFlight = null;',
|
||||
' var pageAuthRenewalSkewMs = ' + JSON.stringify(renewSkewMs) + ';',
|
||||
@@ -287,11 +290,28 @@ function createPageFetchAuthScript(token) {
|
||||
' });',
|
||||
' }, delayMs);',
|
||||
' }',
|
||||
' function writePageAuthCookie(nextToken, nextExpiresAt) {',
|
||||
' if (!pageAuthCookiePath) {',
|
||||
' return;',
|
||||
' }',
|
||||
' var cookieParts = [pageAuthCookieName + "=" + encodeURIComponent(String(nextToken || "").trim()), "Path=" + pageAuthCookiePath, "SameSite=Lax"];',
|
||||
' var expiresInMs = Number(nextExpiresAt || 0) - Date.now();',
|
||||
' if (Number.isFinite(expiresInMs) && expiresInMs > 0) {',
|
||||
' cookieParts.push("Max-Age=" + Math.max(1, Math.floor(expiresInMs / 1000)));',
|
||||
' } else {',
|
||||
' cookieParts.push("Max-Age=0");',
|
||||
' }',
|
||||
' if (window.location.protocol === "https:") {',
|
||||
' cookieParts.push("Secure");',
|
||||
' }',
|
||||
' document.cookie = cookieParts.join("; ");',
|
||||
' }',
|
||||
' function setPageAuthToken(nextToken, nextExpiresAt) {',
|
||||
' pageAuthToken = String(nextToken || "").trim();',
|
||||
' pageAuthExpiresAt = Number(nextExpiresAt || 0) || null;',
|
||||
' window.__pulsePageAuthToken = pageAuthToken;',
|
||||
' window.__pulsePageAuthExpiresAt = pageAuthExpiresAt;',
|
||||
' writePageAuthCookie(pageAuthToken, pageAuthExpiresAt);',
|
||||
' schedulePageAuthRenewal();',
|
||||
' }',
|
||||
' async function renewPageAuthToken() {',
|
||||
@@ -326,6 +346,7 @@ function createPageFetchAuthScript(token) {
|
||||
' window.__pulseRenewPageAuthToken = renewPageAuthToken;',
|
||||
' window.__pulsePageAuthToken = pageAuthToken;',
|
||||
' window.__pulsePageAuthExpiresAt = pageAuthExpiresAt;',
|
||||
' writePageAuthCookie(pageAuthToken, pageAuthExpiresAt);',
|
||||
' window.addEventListener("focus", function () {',
|
||||
' schedulePageAuthRenewal();',
|
||||
' });',
|
||||
|
||||
Reference in New Issue
Block a user