|
9 | 9 | * @license For private project or commercial purposes contact us at: license.mirotalk@gmail.com or purchase it directly via Code Canyon: |
10 | 10 | * @license https://codecanyon.net/item/mirotalk-c2c-webrtc-real-time-cam-2-cam-video-conferences-and-screen-sharing/43383005 |
11 | 11 | * @author Miroslav Pejic - miroslav.pejic.85@gmail.com |
12 | | - * @version 1.2.78 |
| 12 | + * @version 1.2.79 |
13 | 13 | */ |
14 | 14 |
|
15 | 15 | require('dotenv').config(); |
@@ -211,28 +211,32 @@ app.use((err, req, res, next) => { |
211 | 211 |
|
212 | 212 | // OpenID Connect - Dynamically set baseURL based on incoming host and protocol |
213 | 213 | if (OIDC.enabled) { |
214 | | - const getDynamicConfig = (host, protocol) => { |
215 | | - const baseURL = `${protocol}://${host}`; |
| 214 | + const authMiddlewareCache = new Map(); |
216 | 215 |
|
217 | | - const config = OIDC.baseUrlDynamic |
218 | | - ? { |
219 | | - ...OIDC.config, |
220 | | - baseURL, |
221 | | - } |
222 | | - : OIDC.config; |
223 | | - |
224 | | - log.debug('OIDC baseURL', config.baseURL); |
| 216 | + const getAuthMiddleware = (host, protocol) => { |
| 217 | + if (!OIDC.baseUrlDynamic) { |
| 218 | + if (!authMiddlewareCache.has('static')) { |
| 219 | + log.debug('OIDC baseURL', OIDC.config.baseURL); |
| 220 | + authMiddlewareCache.set('static', auth(OIDC.config)); |
| 221 | + } |
| 222 | + return authMiddlewareCache.get('static'); |
| 223 | + } |
225 | 224 |
|
226 | | - return config; |
| 225 | + const key = `${protocol}://${host}`; |
| 226 | + if (!authMiddlewareCache.has(key)) { |
| 227 | + const config = { ...OIDC.config, baseURL: key }; |
| 228 | + log.debug('OIDC baseURL', config.baseURL); |
| 229 | + authMiddlewareCache.set(key, auth(config)); |
| 230 | + } |
| 231 | + return authMiddlewareCache.get(key); |
227 | 232 | }; |
228 | 233 |
|
229 | | - // Apply the authentication middleware using dynamic baseURL configuration |
| 234 | + // Apply the cached authentication middleware |
230 | 235 | app.use((req, res, next) => { |
231 | 236 | const host = req.headers.host; |
232 | 237 | const protocol = req.protocol === 'https' ? 'https' : 'http'; |
233 | | - const dynamicOIDCConfig = getDynamicConfig(host, protocol); |
234 | 238 | try { |
235 | | - auth(dynamicOIDCConfig)(req, res, next); |
| 239 | + getAuthMiddleware(host, protocol)(req, res, next); |
236 | 240 | } catch (err) { |
237 | 241 | log.error('OIDC Auth Middleware Error', err); |
238 | 242 | process.exit(1); |
|
0 commit comments