Hi, All, Apex 24.2.5
https://www.cengizsevimli.com/blog/time-based-one-time-password-oracle-apex
Cengiz's code works fine, only one part is missing: after username/password is accepted, how do I verify the input TOTP code? I can't find an Apex example with bank app style blocking overlay, so I made one with JS prompt, my JS skill is very rudimental, any suggestions or code snippets are appreciated, I have seen quite a few Javascript gurus here , say, Karel.
RESULTS: mostly working. if I click Cancel on Prompt() , a small red error is displayed then quickly disappears , I got LOGIN screen, i can't find out what error for Logout_URL redirect.
Question: is it the right way for 2FA by implementing TOTP code verification as an Overlay during home page load?
>event: Page load
code:
let mfa_required='&AI_MFA_REQUIRED.'; // AI_MFA_REQUIRED is application item
// acting as global flag, it is set to Y during logon
if (mfa_required !=='Y') return; //verified already
code_verify();
function code_verify(){
let code=prompt('Please enter the 6 digit code from your MFA Authenticator here');
if (code===null) {//cancel button clicked
apex.navigation.redirect('&LOGOUT_URL.', true);
return;
}
//sanity check
if (code.length !==6 || ! /^\d+$/.test(code)) {
alert('Code must be 6 digits only, please try again:');
code_verify();
return;
}
//entered 6 digits here
apex.server.process("MFA_VERIFY_AJAX", { x01: code}, {
dataType: 'text'
}).done(function (pData) {
if (pData==='Y') {
return;
}else{
alert('You entered wrong code:'+code+', please try again');
code_verify();
}
}) ;
}
//Ajax
DECLARE
code_correct boolean;
code_input varchar2(10);
l_result char;
-----we only want to check once per login
begin
code_input:= apex_application.g_x01;
-----check if it's the correct TOTP
code_correct:=sdkuser.auth_pkg.f_check_totp(:AI_REPCODE , code_input);
if code_correct then
:AI_MFA_REQUIRED:='N';
l_result:='Y';
else
l_result:='N';
end if;
htp.prn(l_result);
END;
