From 6f4c609ac152197c29b1a55408f0b0a6cec8edc7 Mon Sep 17 00:00:00 2001 From: Miroslav Pejic Date: Thu, 6 Feb 2025 10:35:32 +0100 Subject: [PATCH] [mirotalksfu] - improve OIDC auth check --- app/src/Server.js | 36 +++++++++++++++++++++++------------- package.json | 2 +- public/js/Brand.js | 2 +- public/js/Room.js | 4 ++-- public/js/RoomClient.js | 2 +- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/app/src/Server.js b/app/src/Server.js index 1a041855..3850224e 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -58,7 +58,7 @@ dev dependencies: { * @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon * @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 * @author Miroslav Pejic - miroslav.pejic.85@gmail.com - * @version 1.7.23 + * @version 1.7.24 * */ @@ -328,23 +328,33 @@ if (!announcedAddress && IPv4 === '0.0.0.0') { // Custom middleware function for OIDC authentication function OIDCAuth(req, res, next) { if (OIDC.enabled) { + + function handleHostProtected(req) { + if (!hostCfg.protected) return; + + const ip = authHost.getIP(req); + hostCfg.authenticated = true; + authHost.setAuthorizedIP(ip, true); + // Check... + log.debug('OIDC ------> Host protected', { + authenticated: hostCfg.authenticated, + authorizedIPs: authHost.getAuthorizedIPs(), + }); + } + + if (req.oidc.isAuthenticated()) { + log.debug('OIDC ------> User already Authenticated'); + handleHostProtected(req); + return next(); + } + // Apply requiresAuth() middleware conditionally requiresAuth()(req, res, function () { - log.debug('[OIDC] ------> requiresAuth'); + log.debug('OIDC ------> requiresAuth'); // Check if user is authenticated if (req.oidc.isAuthenticated()) { log.debug('[OIDC] ------> User isAuthenticated'); - // User is authenticated - if (hostCfg.protected) { - const ip = authHost.getIP(req); - hostCfg.authenticated = true; - authHost.setAuthorizedIP(ip, true); - // Check... - log.debug('[OIDC] ------> Host protected', { - authenticated: hostCfg.authenticated, - authorizedIPs: authHost.getAuthorizedIPs(), - }); - } + handleHostProtected(req); next(); } else { // User is not authenticated diff --git a/package.json b/package.json index 5084f5cc..fc4f509b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mirotalksfu", - "version": "1.7.23", + "version": "1.7.24", "description": "WebRTC SFU browser-based video calls", "main": "Server.js", "scripts": { diff --git a/public/js/Brand.js b/public/js/Brand.js index cb9db3ec..2595f78f 100644 --- a/public/js/Brand.js +++ b/public/js/Brand.js @@ -64,7 +64,7 @@ let BRAND = { }, about: { imageUrl: '../images/mirotalk-logo.gif', - title: 'WebRTC SFU v1.7.23', + title: 'WebRTC SFU v1.7.24', html: `