@@ -10,6 +10,7 @@ if (fs.existsSync(userSettingsPath)) {
1010let _authorisedList = defaultSettings . authorisedList ;
1111let _database = defaultSettings . sink ;
1212let _authentication = defaultSettings . authentication ;
13+ let _apiAuthentication = defaultSettings . apiAuthentication ;
1314let _tempPassword = defaultSettings . tempPassword ;
1415let _proxyUrl = defaultSettings . proxyUrl ;
1516let _api = defaultSettings . api ;
@@ -88,6 +89,24 @@ const getAuthMethods = () => {
8889 return enabledAuthMethods ;
8990} ;
9091
92+ /**
93+ * Get the list of enabled authentication methods for API endpoints
94+ * @return {Array } List of enabled authentication methods
95+ */
96+ const getAPIAuthMethods = ( ) => {
97+ if ( _userSettings !== null && _userSettings . apiAuthentication ) {
98+ _apiAuthentication = _userSettings . apiAuthentication ;
99+ }
100+
101+ const enabledAuthMethods = _apiAuthentication . filter ( auth => auth . enabled ) ;
102+
103+ if ( enabledAuthMethods . length === 0 ) {
104+ throw new Error ( "No authentication method enabled." ) ;
105+ }
106+
107+ return enabledAuthMethods ;
108+ } ;
109+
91110// Log configuration to console
92111const logConfiguration = ( ) => {
93112 console . log ( `authorisedList = ${ JSON . stringify ( getAuthorisedList ( ) ) } ` ) ;
@@ -205,6 +224,7 @@ exports.getAuthorisedList = getAuthorisedList;
205224exports . getDatabase = getDatabase ;
206225exports . logConfiguration = logConfiguration ;
207226exports . getAuthMethods = getAuthMethods ;
227+ exports . getAPIAuthMethods = getAPIAuthMethods ;
208228exports . getTempPasswordConfig = getTempPasswordConfig ;
209229exports . getCookieSecret = getCookieSecret ;
210230exports . getSessionMaxAgeHours = getSessionMaxAgeHours ;
0 commit comments