🔐 Summary: Two-Factor Authentication (2FA) Implementation in AwareIM
I’ve implemented a flexible 2FA system in AwareIM that supports both SMS and email verification, based on a system-wide setting. Below is a short overview of the setup.
This approach provides:
- Flexible control via system settings
- External SMS integration using REST
- A simple and user-friendly HTML interface
⚙️ Configuration
The 2FA method is defined in the SystemSettings.Method2FA
attribute with the following options:
—
📦 Business Objects
- Login2FA: stores the generated code (
Code2FA
) and user input (Code2FAInput
), with a reference to ps_BackofficeUser
- SMSService: handles REST call to BulkGate API
- SMSRequest and SMSResponse: support request and response data
—
🔁 Process Flow
1. Initialise
Called during user login or session startup. Checks which 2FA method is active and starts SendSMS
or SendEmail
accordingly.
IF SystemSettings.Method2FA='SMS'
AND SystemSettings.SMSKey IS DEFINED
AND LoggedInBackofficeUser.TelNrMobiel IS DEFINED THEN
DISPLAY PERSPECTIVE Login2FA
SendSMS
ELSE IF SystemSettings.Method2FA='Email'
AND SystemSettings.ps_Template2FA IS DEFINED
AND LoggedInBackofficeUser.EmailAddress IS DEFINED THEN
DISPLAY PERSPECTIVE Login2FA
SendEmail
2. SendSMS
- Creates a
Login2FA
record and generates a 6-digit code
- Sends the code using a REST call to BulkGate
- Displays a custom HTML form to enter the code
CREATE Login2FA WITH
ps_BackofficeUser=LoggedInBackofficeUser,
Code2FA=GENERATE_PWD(6,6,0,6,0),
Code2FAInput=''
CREATE SMSRequest WITH SMSRequest.Request='{
`application_id`: `' + SystemSettings.SMSApplicationID + '`,
`application_token`: `' + SystemSettings.SMSKey + '`,
`number`: `' + LoggedInBackofficeUser.TelNrMobiel + '`,
`text`: `Je verificatiecode is: ' + Login2FA.Code2FA + '`,
`sender_id`: `system_number`,
`unicode`: true,
`country`: `NL`
}'
REQUEST SERVICE SendLoginCode OF SMSService
VIEW Login2FA USING HTML
3. SendEmail
- Same logic as SMS, but sends the code via email using a predefined template
CREATE Login2FA WITH
ps_BackofficeUser=LoggedInBackofficeUser,
Code2FA=GENERATE_PWD(6,6,0,6,0),
Code2FAInput=''
FIND Templates WHERE Templates=SystemSettings.ps_Template2FA TAKE BEST 1
CREATE OutgoingEmail WITH
SentToAddress=LoggedInBackofficeUser.EmailAddress,
Subject=Templates.Subject,
Message=Templates.Message
CREATE OutboundEmail WITH
FromAddress=SystemSettings.OutgoingEmailFromAddress,
Subject=OutgoingEmail.Subject,
Message=OutgoingEmail.Message
SEND OutboundEmail TO LoggedInBackofficeUser
VIEW Login2FA USING HTML
4. Check2FA
- Compares user input to the generated code
- If incorrect, shows an error and clears the input
- If valid, displays the target perspective (e.g.,
Administrator
)
IF SystemSettings.Method2FA IN 'SMS', 'Email'
AND LoggedInSystemUser.AccessLevel IN 'Administrator', 'BackendUser'
AND (Login2FA.Code2FA<>Login2FA.Code2FAInput OR Code2FAInput IS UNDEFINED) THEN
DISPLAY MESSAGE 'Wrong verification code. Please try again.'
Login2FA.Code2FAInput=''
ELSE
DISPLAY PERSPECTIVE Administrator
📜 HTML Input Form
<html>
<body>
<div class="box">
<h2>Enter verification code</h2>
<form class="form-control">
<input class="aw-mapped" type="text" maxlength="6" placeholder="e.g., 123456" aw_attr_id="101">
<br>
<button class="btn aw-selected aw-mapped" type="submit" aw_oper_id="4">Verify</button>
</form>
</div>
</body>
</html>