Skip to content

Commit

Permalink
feat: allow user to enter acr directly #8615 (#8622)
Browse files Browse the repository at this point in the history
* feat: allow user to enter acr directly #8615

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>

* feat: add docs image

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>

---------

Signed-off-by: Arnab Dutta <arnab.bdutta@gmail.com>
Former-commit-id: c1deb30
  • Loading branch information
duttarnab authored Jun 3, 2024
1 parent 6758a49 commit 80cec06
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 21 deletions.
81 changes: 60 additions & 21 deletions demos/jans-tarp/src/options/authFlowInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ import MenuItem from '@mui/material/MenuItem';
import { IOption } from './IOption';
import Alert from '@mui/material/Alert';
import { ILooseObject } from './ILooseObject';

import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
const createOption = (label: string) => ({
label,
value: label,
name: label,
});

const filter = createFilterOptions();
export default function AuthFlowInputs({ isOpen, handleDialog, client }) {
const [open, setOpen] = React.useState(isOpen);
const [errorMessage, setErrorMessage] = React.useState("")
const [additionalParamError, setAdditionalParamError] = React.useState("")
const [displayToken, setDisplayToken] = React.useState(false);
const [acrValues, setAcrValues] = React.useState<readonly IOption[]>([]);
const [acrValueOption, setAcrValueOption] = React.useState("");
const [additionalParams, setAdditionalParams] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [acrValueOption, setAcrValueOption] = React.useState([]);
const [selectedAcr, setSelectedAcr] = React.useState([])


React.useEffect(() => {
Expand All @@ -47,14 +46,10 @@ export default function AuthFlowInputs({ isOpen, handleDialog, client }) {

React.useEffect(() => {
(async () => {
setAcrValues(client.acrValuesSupported.map((ele) => createOption(ele)));
setAcrValueOption(client.acrValuesSupported.map((ele) => createOption(ele)));
})();
}, [])

const handleAcrChange = (event) => {
setAcrValueOption(event.target.value);
};

const handleClose = () => {
handleDialog(false)
setOpen(false);
Expand Down Expand Up @@ -94,8 +89,8 @@ export default function AuthFlowInputs({ isOpen, handleDialog, client }) {
nonce: uuidv4(),
};

if (!!acrValueOption) {
options.acr_values = acrValueOption;
if (!!selectedAcr && selectedAcr.length > 0) {
options.acr_values = selectedAcr[0].name;
}

let authzUrl = `${client?.authorizationEndpoint}?${qs.stringify(options)}`;
Expand Down Expand Up @@ -314,15 +309,59 @@ export default function AuthFlowInputs({ isOpen, handleDialog, client }) {
/>

<InputLabel id="acr-value-label">Acr Value</InputLabel>
<Select
labelId="acr-value-label"
<Autocomplete
value={selectedAcr}
multiple
defaultValue={[acrValueOption[0]]}
onChange={(event, newValue, reason, details) => {
if (reason === 'removeOption') {
setSelectedAcr([]);
} else if (reason === 'selectOption') {
setSelectedAcr([{id: undefined, name: details.option.name}]);
} else if(reason === 'createOption') {
setSelectedAcr([{id: undefined, name: details.option}]);
}
}}
filterSelectedOptions
filterOptions={(options, params) => {
const filtered = filter(options, params);

const { inputValue } = params;
// Suggest the creation of a new value
const isExisting = options.some((option) => inputValue === option.name);
if (inputValue !== '' && !isExisting) {
filtered.push({
name: inputValue,
label: `Add "${inputValue}"`,
create: true
});
}

return filtered;
}}
//selectOnFocus
clearOnBlur
handleHomeEndKeys
id="acrValue"
onChange={handleAcrChange}
>
{acrValues.map((ele) => (
<MenuItem value={ele.label}>{ele.label}</MenuItem>
))}
</Select>
options={acrValueOption}
getOptionLabel={(option) => {
// Value selected with enter, right from the input
if (typeof option === 'string') {
return option;
}
// Add "xxx" option created dynamically
if (option.label) {
return option.name;
}
// Regular option
return option.name;
}}
renderOption={(props, option) => <li {...props}>{option.create ? option.label : option.name}</li>}
freeSolo
renderInput={(params) => (
<TextField {...params} label="Acr Values" />
)}
/>
<FormControlLabel control={<Checkbox color="success" onChange={() => setDisplayToken(!displayToken)}/>} label="Display Access Token and ID Token after authentication" />
</Stack>
</DialogContent>
Expand Down
16 changes: 16 additions & 0 deletions demos/jans-tarp/src/options/helpDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ export default function HelpDrawer({ isOpen, handleDrawer }) {
/>
</Card>
</Box>
<Box sx={{ width: 575 }} role="presentation">
<Card sx={{ maxWidth: 575 }}>
<CardContent>
<Typography gutterBottom variant="h5" component="div">
Optional
</Typography>
<Typography variant="body2" color="text.secondary">
For <b>'Acr Values'</b> input, you can also add a new ACR option.
</Typography>
</CardContent>
<CardMedia
sx={{ height: 459 }}
image={'tarpDocs5.png'}
/>
</Card>
</Box>
</>
);

Expand Down
Binary file modified demos/jans-tarp/src/static/tarpDocs1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demos/jans-tarp/src/static/tarpDocs2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demos/jans-tarp/src/static/tarpDocs3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demos/jans-tarp/src/static/tarpDocs4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/jans-tarp/src/static/tarpDocs5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions demos/jans-tarp/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const assetArr = [{
},
{
from: path.resolve('src/static/tarpDocs4.png')
},
{
from: path.resolve('src/static/tarpDocs5.png')
}];

const chromeConfig = merge(commonConfig, {
Expand Down

0 comments on commit 80cec06

Please sign in to comment.