Skip to content

Commit

Permalink
QRCode buffer configuration added
Browse files Browse the repository at this point in the history
  • Loading branch information
anshulv1401 committed Jul 24, 2023
1 parent e16bb02 commit 33ceb02
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mosip.esignet.ui.config.key-values={'sbi.env': 'Developer', 'sbi.timeout.DISC':
'send.otp.channels':'email,phone', 'consent.screen.timeout-in-secs':${mosip.esignet.authentication-expire-in-secs}, \
'consent.screen.timeout-buffer-in-secs': 5, 'sbi.port.range': 4501-4600, 'sbi.bio.subtypes.iris': 'UNKNOWN', 'sbi.bio.subtypes.finger': 'UNKNOWN', \
'resend.otp.delay.secs': 120, 'captcha.enable': 'OTP', 'captcha.sitekey': '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI', \
'mosip.esignet.link-auth-code-expire-in-secs': 120, 'mosip.esignet.link-status-deferred-response-timeout-secs': 25, \
'mosip.esignet.link-auth-code-expire-in-secs': 120, 'wallet.qr-code-buffer-in-secs': 10, \
'mosip.esignet.qr-code.deep-link-uri': 'inji://landing-page-name?linkCode=LINK_CODE&linkExpireDateTime=LINK_EXPIRE_DT', \
'mosip.esignet.qr-code.download-uri': '#', 'mosip.esignet.qr-code.enable': 'true', 'auth.txnid.length': 10, \
'otp.length': 6, 'password.regex': ''}
2 changes: 1 addition & 1 deletion oidc-ui/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REACT_APP_SBI_IRIS_BIO_SUBTYPES="UNKNOWN"
REACT_APP_SBI_FINGER_BIO_SUBTYPES="UNKNOWN"

REACT_APP_LINK_AUTH_CODE_TIMEOUT_IN_SEC=120
REACT_APP_LINK_CODE_DEFERRED_TIMEOUT_IN_SEC=25
REACT_APP_QR_CODE_BUFFER_IN_SEC=10
REACT_APP_QRCODE_DEEP_LINK_URI="inji://landing-page-name?linkCode=LINK_CODE&linkExpireDateTime=LINK_EXPIRE_DT"
REACT_APP_QRCODE_APP_DOWNLOAD_URI="#"
REACT_APP_QRCODE_ENABLE="true"
Expand Down
6 changes: 5 additions & 1 deletion oidc-ui/public/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"invalid_value": "قيمة غير صالحة",
"duplicate_individual_id": "المعرف الفردي موجود بالفعل.",
"password_error_msg": "رمز مرور خاطئ",
"invalid_qrcode_config": "تكوين QRCode غير صالح. يرجى إبلاغ مدير الموقع.",
"0": "النجاح",
"100": "الجهاز غير مسجل",
"101": "غير قادر على الكشف عن كائن القياسات الحيوية",
Expand Down Expand Up @@ -344,6 +345,9 @@
"IDA-RST-005": "المهلة غير صالحة",
"IDA-RST-006": "4XX - حدث خطأ في العميل",
"IDA-RST-007": "5XX - حدث خطأ في الخادم",
"IDA-RST-008": "انتهت مدة الاتصال"
"IDA-RST-008": "انتهت مدة الاتصال",
"IDA-KBT-001": "لم يتم العثور على الشهادة المنضمة",
"IDA-KBT-002": "الرمز المميز الموقع الصادر في (iat) ليس في النطاق الزمني المسموح به.",
"IDA-KBT-003": "خطأ في التحقق من الرمز المميز المرتبط بالمفتاح."
}
}
6 changes: 5 additions & 1 deletion oidc-ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
"invalid_value": "Invalid value",
"duplicate_individual_id": "Individual ID already exists.",
"password_error_msg": "Invalid Password",
"invalid_qrcode_config": "Invalid QRCode configuration. Please report to the site admin.",
"0": "Success",
"100": "Device Not Registered",
"101": "Unable to Detect a Biometrics",
Expand Down Expand Up @@ -344,6 +345,9 @@
"IDA-RST-005": "Timeout is invalid",
"IDA-RST-006": "4XX - Client Error occurred",
"IDA-RST-007": "5XX - Server Error occurred",
"IDA-RST-008": "Connection timed out"
"IDA-RST-008": "Connection timed out",
"IDA-KBT-001": "Bound certificate not found",
"IDA-KBT-002": "Signed token issued at (iat) is not in allowed time range.",
"IDA-KBT-003": "Error verifying key binded token."
}
}
74 changes: 48 additions & 26 deletions oidc-ui/src/components/LoginQRCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@ export default function LoginQRCode({
const [qr, setQr] = useState("");
const [status, setStatus] = useState({ state: states.LOADED, msg: "" });
const [error, setError] = useState(null);
const [qrCodeTimeOut, setQrCodeTimeout] = useState();

const linkAuthCodeExpireInSec =
openIDConnectService.getEsignetConfiguration(
configurationKeys.linkAuthCodeExpireInSec
) ?? process.env.REACT_APP_LINK_AUTH_CODE_TIMEOUT_IN_SEC;

/*
linkCodeDeferredTimeoutInSec is link_status Grace period. link-status request will not be triggered
if the linkCode is going to expire within grace period.
The QRCode will be valid even after expiring on the UI for the period of qrCodeBufferInSecs.
*/
const linkCodeDeferredTimeoutInSec =
const qrCodeBufferInSecs =
openIDConnectService.getEsignetConfiguration(
configurationKeys.linkCodeDeferredTimeoutInSec
) ?? process.env.REACT_APP_LINK_CODE_DEFERRED_TIMEOUT_IN_SEC;
configurationKeys.qrCodeBufferInSecs
) ?? process.env.REACT_APP_QR_CODE_BUFFER_IN_SEC;

let parseTimeout = parseInt(linkCodeDeferredTimeoutInSec);

const linkStatusGracePeriod = parseTimeout !== "NaN" ? parseTimeout : 25;
const qrCodeBuffer =
parseInt(qrCodeBufferInSecs) !== "NaN"
? parseInt(qrCodeBufferInSecs)
: process.env.REACT_APP_QR_CODE_BUFFER_IN_SEC;

const walletLogoURL =
openIDConnectService.getEsignetConfiguration(
configurationKeys.walletLogoURL
) ?? process.env.REACT_APP_WALLET_LOGO_URL;
openIDConnectService.getEsignetConfiguration(
configurationKeys.walletLogoURL
) ?? process.env.REACT_APP_WALLET_LOGO_URL;

const GenerateQRCode = (response, logoUrl) => {
let text =
Expand Down Expand Up @@ -104,9 +105,8 @@ export default function LoginQRCode({
logo.onerror = () => {
// If there's an error fetching the logo, generate QR code without the logo
setQr(canvas.toDataURL());
}
}
else {
};
} else {
// If logoUrl is not configured, generate QR code without the logo
setQr(canvas.toDataURL());
}
Expand All @@ -116,6 +116,11 @@ export default function LoginQRCode({

useEffect(() => {
fetchQRCode();

return () => {
//clearing timeout before component unmount
clearTimeout(qrCodeTimeOut);
};
}, []);

const fetchQRCode = async () => {
Expand All @@ -136,13 +141,42 @@ export default function LoginQRCode({
defaultMsg: errors[0].errorMessage,
});
} else {
let qrCodeExpiryDateTime = new Date(response.expireDateTime);
let timeLeft = (qrCodeExpiryDateTime - new Date()) / 1000; // timeleft in sec

if (qrCodeBuffer > (timeLeft + 1) / 2) {
/*
qrCodeBuffer should not be greater then the half of link-code-expire-in-secs.
It reduces the chances of more then 2 active link-status polling request at a time.
*/
setError({
errorCode: "invalid_qrcode_config",
defaultMsg:
"Invalid QRCode configuration. Please report to the site admin.",
});
return;
}

/*
considering buffer time before next qrcode render, which will allow previous
qrcode's link-status polling request to be active for the buffer period.
*/
let timeLeftWithBuffer = timeLeft - qrCodeBuffer;

GenerateQRCode(response, walletLogoURL);
setStatus({ state: states.LOADED, msg: "" });
triggerLinkStatus(
response.transactionId,
response.linkCode,
response.expireDateTime
);

clearTimeout(qrCodeTimeOut);
let _timer = setTimeout(() => {
if (linkAuthTriggered) return;
fetchQRCode();
}, timeLeftWithBuffer * 1000);
setQrCodeTimeout(_timer);
}
} catch (error) {
setError({
Expand All @@ -161,7 +195,6 @@ export default function LoginQRCode({
try {
let expiryDateTime = new Date(linkCodeExpiryDateTime);
let timeLeft = (expiryDateTime - new Date()) / 1000; // timeleft in sec
let qrExpired = false;
let linkStatusResponse;
while (timeLeft > 0) {
try {
Expand All @@ -187,17 +220,6 @@ export default function LoginQRCode({
}

timeLeft = (expiryDateTime - new Date()) / 1000;
if (
!qrExpired &&
timeLeft < linkStatusGracePeriod &&
(!linkStatusResponse || !linkStatusResponse?.response)
) {
qrExpired = true;
// setError({
// errorCode: "qr_code_expired",
// });
fetchQRCode();
}
}

if (linkAuthTriggered) return;
Expand Down
2 changes: 1 addition & 1 deletion oidc-ui/src/constants/clientConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const configurationKeys = {
captchaSiteKey: "captcha.sitekey", //site key for ReCAPTCHA

linkAuthCodeExpireInSec: "mosip.esignet.link-auth-code-expire-in-secs",
linkCodeDeferredTimeoutInSec: "mosip.esignet.link-status-deferred-response-timeout-secs",
qrCodeBufferInSecs: "wallet.qr-code-buffer-in-secs",
qrCodeDeepLinkURI: "mosip.esignet.qr-code.deep-link-uri",
appDownloadURI: "mosip.esignet.qr-code.download-uri",
signInWithQRCodeEnable: "mosip.esignet.qr-code.enable",
Expand Down

0 comments on commit 33ceb02

Please sign in to comment.