Skip to content

Commit 74d241e

Browse files
Defualt Acr request issue resolved
1 parent 64e0550 commit 74d241e

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

admin-ui/plugins/auth-server/components/AuthN/DefaultAcr.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import GluuLoader from '@/routes/Apps/Gluu/GluuLoader'
1414
import { ThemeContext } from '@/context/theme/themeContext'
1515
import DefaultAcrInput from '../Configuration/DefaultAcrInput'
1616
import { getScripts } from 'Redux/features/initSlice'
17-
import { SIMPLE_PASSWORD_AUTH } from 'Plugins/auth-server/common/Constants'
17+
import { buildAgamaFlowsArray, buildDropdownOptions } from './helper/acrUtils'
1818

1919
function DefaultAcr() {
2020
const { hasCedarPermission, authorize } = useCedarling()
@@ -52,19 +52,17 @@ function DefaultAcr() {
5252
}, [authorize, dispatch])
5353

5454
const authScripts = useMemo(() => {
55+
// Filter and map scripts
5556
const filteredScripts = scripts
5657
.filter((item) => item.scriptType == 'person_authentication')
5758
.filter((item) => item.enabled)
58-
.map((item) => item.name)
59+
.map((item) => ({ key: item.name, value: item.name }))
60+
// Build individual agama flows array
61+
const agamaFlows = buildAgamaFlowsArray(agamaList)
62+
// Build dropdown options (each flow is a separate entry)
63+
const dropdownOptions = buildDropdownOptions(filteredScripts, agamaFlows)
5964

60-
const agamaFlows = Array.isArray(agamaList)
61-
? agamaList.map((flow) => flow?.details?.projectMetadata?.projectName).filter(Boolean)
62-
: []
63-
64-
filteredScripts.push(SIMPLE_PASSWORD_AUTH)
65-
const result = Array.from(new Set([...filteredScripts, ...agamaFlows])).sort()
66-
67-
return result
65+
return dropdownOptions
6866
}, [scripts, agamaList])
6967

7068
const toggle = () => {
@@ -89,12 +87,10 @@ function DefaultAcr() {
8987

9088
if (put?.value) {
9189
const opts = {}
92-
opts['authenticationMethod'] = { defaultAcr: put?.value }
90+
opts['authenticationMethod'] = { defaultAcr: put.value }
9391

9492
buildPayload(userAction, userMessage, opts)
9593
dispatch(editAcrs({ data: opts, action: userAction }))
96-
} else {
97-
console.error('No ACR value to save')
9894
}
9995
}
10096

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { SIMPLE_PASSWORD_AUTH } from 'Plugins/auth-server/common/Constants'
2+
3+
/**
4+
* Build agama flows array from agama list
5+
* Extracts individual flows that are not in noDirectLaunch and adds agama_ prefix
6+
* Each flow becomes a separate entry
7+
* @param {Array} agamaList - List of agama deployments
8+
* @returns {Array} Array of qualified flow names
9+
*/
10+
export const buildAgamaFlowsArray = (agamaList) => {
11+
const agamaFlows = []
12+
if (Array.isArray(agamaList)) {
13+
agamaList.forEach((flow) => {
14+
const configs = flow?.details?.projectMetadata?.configs
15+
const noDirectLaunch = flow?.details?.projectMetadata?.noDirectLaunch || []
16+
17+
if (configs) {
18+
Object.keys(configs).forEach((key) => {
19+
if (!noDirectLaunch.includes(key)) {
20+
const qualifiedName = `agama_${key}`
21+
agamaFlows.push(qualifiedName)
22+
}
23+
})
24+
}
25+
})
26+
}
27+
return agamaFlows
28+
}
29+
30+
/**
31+
* Build dropdown options array
32+
* Combines scripts, SIMPLE_PASSWORD_AUTH, and individual agama flows into sorted array
33+
* Each entry maps to itself (display name = value)
34+
* @param {Array} filteredScripts - Filtered authentication scripts
35+
* @param {Array} agamaFlows - Array of agama flows
36+
* @returns {Array} Sorted array of dropdown options
37+
*/
38+
export const buildDropdownOptions = (filteredScripts, agamaFlows) => {
39+
const scriptNames = filteredScripts.map((s) => s.key)
40+
41+
return [...scriptNames, SIMPLE_PASSWORD_AUTH, ...agamaFlows].sort()
42+
}

0 commit comments

Comments
 (0)