-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds document attribute for disable tcpcheck #4008
Changes from 4 commits
b7caf04
e3f891c
1fb0787
d142603
150d805
a6752a2
7a18906
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,10 @@ class LifecycleManager extends LuigiClientBase { | |
/** @private */ | ||
constructor() { | ||
super(); | ||
this.disableTpcCheck = false; | ||
this.luigiInitialized = false; | ||
this.defaultContextKeys = ['context', 'internal', 'nodeParams', 'pathParams', 'searchParams']; | ||
this.setCurrentContext( | ||
this.defaultContextKeys.reduce(function(acc, key) { | ||
this.defaultContextKeys.reduce(function (acc, key) { | ||
acc[key] = {}; | ||
return acc; | ||
}, {}) | ||
|
@@ -38,6 +37,15 @@ class LifecycleManager extends LuigiClientBase { | |
return window.document.head.hasAttribute('defer-luigi-init'); | ||
} | ||
|
||
/** | ||
* Check if the html head element contains the attribute "disable-tpc-check" | ||
* @private | ||
* @memberof Lifecycle | ||
*/ | ||
_isTpcCheckDisabled() { | ||
return window.document.head.hasAttribute('disable-tpc-check'); | ||
} | ||
|
||
/** | ||
* Check if LuigiClient is initialized | ||
* @returns {boolean} client initialized state | ||
|
@@ -66,7 +74,7 @@ class LifecycleManager extends LuigiClientBase { | |
* Save context data every time navigation to a different node happens | ||
* @private | ||
*/ | ||
const setContext = rawData => { | ||
const setContext = (rawData) => { | ||
for (let index = 0; index < this.defaultContextKeys.length; index++) { | ||
let key = this.defaultContextKeys[index]; | ||
try { | ||
|
@@ -80,13 +88,13 @@ class LifecycleManager extends LuigiClientBase { | |
this.setCurrentContext(rawData); | ||
}; | ||
|
||
const setAuthData = eventPayload => { | ||
const setAuthData = (eventPayload) => { | ||
if (eventPayload) { | ||
this.authData = eventPayload; | ||
} | ||
}; | ||
|
||
helpers.addEventListener('luigi.init', e => { | ||
helpers.addEventListener('luigi.init', (e) => { | ||
setContext(e.data); | ||
setAuthData(e.data.authData); | ||
helpers.setLuigiCoreDomain(e.origin); | ||
|
@@ -96,15 +104,15 @@ class LifecycleManager extends LuigiClientBase { | |
helpers.sendPostMessageToLuigiCore({ msg: 'luigi.init.ok' }); | ||
}); | ||
|
||
helpers.addEventListener('luigi-client.inactive-microfrontend', e => { | ||
helpers.addEventListener('luigi-client.inactive-microfrontend', (e) => { | ||
this._notifyInactive(e.origin); | ||
}); | ||
|
||
helpers.addEventListener('luigi.auth.tokenIssued', e => { | ||
helpers.addEventListener('luigi.auth.tokenIssued', (e) => { | ||
setAuthData(e.data.authData); | ||
}); | ||
|
||
helpers.addEventListener('luigi.navigate', e => { | ||
helpers.addEventListener('luigi.navigate', (e) => { | ||
setContext(e.data); | ||
if (!this.currentContext.internal.isNavigateBack && !this.currentContext.withoutSync) { | ||
const previousHash = window.location.hash; | ||
|
@@ -140,17 +148,21 @@ class LifecycleManager extends LuigiClientBase { | |
} | ||
|
||
_tpcCheck() { | ||
if (this.currentContext?.internal?.thirdPartyCookieCheck?.disabled || this.disableTpcCheck) { | ||
const tpcCheckDisabled = | ||
this._isTpcCheckDisabled() || this.currentContext?.internal?.thirdPartyCookieCheck?.disabled; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moving the check |
||
|
||
if (tpcCheckDisabled) { | ||
return; | ||
} | ||
|
||
let tpc = 'enabled'; | ||
let cookies = document.cookie; | ||
let luigiCookie; | ||
if (cookies) { | ||
luigiCookie = cookies | ||
.split(';') | ||
.map(cookie => cookie.trim()) | ||
.find(cookie => cookie === 'luigiCookie=true'); | ||
.map((cookie) => cookie.trim()) | ||
.find((cookie) => cookie === 'luigiCookie=true'); | ||
} | ||
if (luigiCookie === 'luigiCookie=true') { | ||
document.cookie = 'luigiCookie=; Max-Age=-99999999; SameSite=None; Secure'; | ||
|
@@ -160,8 +172,8 @@ class LifecycleManager extends LuigiClientBase { | |
if (cookies) { | ||
luigiCookie = cookies | ||
.split(';') | ||
.map(cookie => cookie.trim()) | ||
.find(cookie => cookie === 'luigiCookie=true'); | ||
.map((cookie) => cookie.trim()) | ||
.find((cookie) => cookie === 'luigiCookie=true'); | ||
} | ||
if (luigiCookie === 'luigiCookie=true') { | ||
document.cookie = 'luigiCookie=; Max-Age=-99999999; SameSite=None; Secure'; | ||
|
@@ -225,13 +237,11 @@ class LifecycleManager extends LuigiClientBase { | |
/** | ||
* Registers a listener called with the context object and the Luigi Core domain as soon as Luigi is instantiated. Defer your application bootstrap if you depend on authentication data coming from Luigi. | ||
* @param {Lifecycle~initListenerCallback} initFn the function that is called once Luigi is initialized, receives current context and origin as parameters | ||
* @param {boolean} disableTpcCheck if set to `true` third party cookie check will be disabled via LuigiClient. | ||
* @memberof Lifecycle | ||
* @example | ||
* const initListenerId = LuigiClient.addInitListener((context) => storeContextToMF(context)) | ||
*/ | ||
addInitListener(initFn, disableTpcCheck) { | ||
this.disableTpcCheck = disableTpcCheck; | ||
addInitListener(initFn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the disableTcpCheck argument, it should still be possible to disable via js, e.g. in a test environment. |
||
const id = helpers.getRandomId(); | ||
this._onInitFns[id] = initFn; | ||
if (this.luigiInitialized && helpers.isFunction(initFn)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ class LuigiClient { | |
} | ||
} | ||
|
||
addInitListener(initFn, disableTpcCheck) { | ||
return lifecycleManager.addInitListener(initFn, disableTpcCheck); | ||
addInitListener(initFn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
return lifecycleManager.addInitListener(initFn); | ||
} | ||
removeInitListener(id) { | ||
return lifecycleManager.removeInitListener(id); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep the disableTcpCheck argument, it should still be possible to disable via js, e.g. in a test environment.