Skip to content

Commit 8342e42

Browse files
authored
Merge pull request #204 from kovaceviccz/make-use-of-polling-wait-callback-within-duo-authentication-module
Make use of polling wait callback within Duo authentication module
2 parents eb77f27 + 3d456b0 commit 8342e42

File tree

2 files changed

+30
-9
lines changed
  • openam-server-only/src/main/webapp/config/auth/default
  • openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/login

2 files changed

+30
-9
lines changed

openam-server-only/src/main/webapp/config/auth/default/Duo.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Header, with the fields enclosed by brackets [] replaced by your own identifying
1313
information: "Portions copyright [year] [name of copyright owner]".
1414
15-
Copyright 2023 Wren Security
15+
Copyright 2023-2025 Wren Security
1616
-->
1717
<!DOCTYPE ModuleProperties PUBLIC "=//iPlanet//Authentication Module Properties XML Interface 1.0 DTD//EN"
1818
"jar://com/sun/identity/authentication/Auth_Module_Properties.dtd">
1919

2020
<ModuleProperties moduleName="Duo">
2121
<Callbacks length="0" order="1" timeout="3600" header="#WILL NOT BE SHOWN#" />
22-
<Callbacks length="1" order="2" timeout="3600" header="Login" >
22+
<Callbacks length="2" order="2" timeout="3600" header="Login" >
2323
<TextOutputCallback>Please confirm authentication in your Cisco Duo mobile application.</TextOutputCallback>
24+
<PollingWaitCallback waitTime="5000" />
2425
</Callbacks>
2526
</ModuleProperties>

openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/login/RESTLoginView.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* information: "Portions copyright [year] [name of copyright owner]".
1313
*
1414
* Portions copyright 2011-2016 ForgeRock AS.
15-
* Portions copyright 2024 Wren Security.
15+
* Portions copyright 2024-2025 Wren Security.
1616
*/
1717

1818
define([
@@ -118,6 +118,28 @@ define([
118118
return _.some(requirements.callbacks, ["type", "ConfirmationCallback"]);
119119
}
120120

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+
121143
function getFragmentParamString () {
122144
const params = URIUtils.getCurrentFragmentQueryString();
123145
return _.isEmpty(params) ? "" : `&${params}`;
@@ -333,9 +355,7 @@ define([
333355
const pollingWaitTimeoutMs = _.find(element.output, { name: "waitTime" }).value;
334356

335357
_.delay(() => {
336-
this.pollingInProgress = true;
337-
338-
if (hasPollingCallback(this.reqs)) {
358+
if (this.reqs === reqs) {
339359
EventManager.sendEvent(Constants.EVENT_LOGIN_REQUEST, { suppressSpinner: true });
340360
}
341361
}, pollingWaitTimeoutMs);
@@ -367,16 +387,16 @@ define([
367387
});
368388
}
369389

390+
const renderTemplate = shouldRenderTemplate(this.reqs, reqs);
391+
370392
this.reqs = reqs;
371393
this.data.reqs = requirements;
372394

373-
const pollingInProgress = this.pollingInProgress && hasPollingCallback(reqs);
374-
375395
// Is there an attempt at autologin happening?
376396
// if yes then don't render the form until it fails one time
377397
if (urlParams.IDToken1 && Configuration.globalData.auth.autoLoginAttempts === 1) {
378398
Configuration.globalData.auth.autoLoginAttempts++;
379-
} else if (!pollingInProgress) {
399+
} else if (renderTemplate) {
380400
// Attempt to load a stage-specific template to render this form. If not found, use the generic one.
381401
template = `templates/openam/authn/${reqs.stage}.html`;
382402
UIUtils.compileTemplate(template, _.extend({}, Configuration.globalData, this.data))

0 commit comments

Comments
 (0)