|
12 | 12 | * information: "Portions copyright [year] [name of copyright owner]". |
13 | 13 | * |
14 | 14 | * Portions copyright 2011-2016 ForgeRock AS. |
15 | | - * Portions copyright 2024 Wren Security. |
| 15 | + * Portions copyright 2024-2025 Wren Security. |
16 | 16 | */ |
17 | 17 |
|
18 | 18 | define([ |
@@ -118,6 +118,28 @@ define([ |
118 | 118 | return _.some(requirements.callbacks, ["type", "ConfirmationCallback"]); |
119 | 119 | } |
120 | 120 |
|
| 121 | + /** |
| 122 | + * Decide if the form template needs to be rendered. |
| 123 | + * @param {Object} oldReqs The requirements used for the last render |
| 124 | + * @param {Object} newReqs The newly received requirements |
| 125 | + * @returns {Boolean} `true` when a render is required |
| 126 | + */ |
| 127 | + function shouldRenderTemplate (oldReqs, newReqs) { |
| 128 | + if (!oldReqs || !newReqs || oldReqs.stage !== newReqs.stage) { |
| 129 | + return true; |
| 130 | + } |
| 131 | + if (!oldReqs.callbacks || !newReqs.callbacks || oldReqs.callbacks.length !== newReqs.callbacks.length) { |
| 132 | + return true; |
| 133 | + } |
| 134 | + return _.some(oldReqs, (oldReq, index) => { |
| 135 | + const newReq = newReqs[index]; |
| 136 | + if (oldReq.type === "PollingWaitCallback" && newReq.type === "PollingWaitCallback") { |
| 137 | + return false; |
| 138 | + } |
| 139 | + return !_.isEqual(oldReq, newReq); |
| 140 | + }); |
| 141 | + } |
| 142 | + |
121 | 143 | function getFragmentParamString () { |
122 | 144 | const params = URIUtils.getCurrentFragmentQueryString(); |
123 | 145 | return _.isEmpty(params) ? "" : `&${params}`; |
@@ -333,9 +355,7 @@ define([ |
333 | 355 | const pollingWaitTimeoutMs = _.find(element.output, { name: "waitTime" }).value; |
334 | 356 |
|
335 | 357 | _.delay(() => { |
336 | | - this.pollingInProgress = true; |
337 | | - |
338 | | - if (hasPollingCallback(this.reqs)) { |
| 358 | + if (this.reqs === reqs) { |
339 | 359 | EventManager.sendEvent(Constants.EVENT_LOGIN_REQUEST, { suppressSpinner: true }); |
340 | 360 | } |
341 | 361 | }, pollingWaitTimeoutMs); |
@@ -367,16 +387,16 @@ define([ |
367 | 387 | }); |
368 | 388 | } |
369 | 389 |
|
| 390 | + const renderTemplate = shouldRenderTemplate(this.reqs, reqs); |
| 391 | + |
370 | 392 | this.reqs = reqs; |
371 | 393 | this.data.reqs = requirements; |
372 | 394 |
|
373 | | - const pollingInProgress = this.pollingInProgress && hasPollingCallback(reqs); |
374 | | - |
375 | 395 | // Is there an attempt at autologin happening? |
376 | 396 | // if yes then don't render the form until it fails one time |
377 | 397 | if (urlParams.IDToken1 && Configuration.globalData.auth.autoLoginAttempts === 1) { |
378 | 398 | Configuration.globalData.auth.autoLoginAttempts++; |
379 | | - } else if (!pollingInProgress) { |
| 399 | + } else if (renderTemplate) { |
380 | 400 | // Attempt to load a stage-specific template to render this form. If not found, use the generic one. |
381 | 401 | template = `templates/openam/authn/${reqs.stage}.html`; |
382 | 402 | UIUtils.compileTemplate(template, _.extend({}, Configuration.globalData, this.data)) |
|
0 commit comments