diff --git a/src/components/JwtSection/JwtForm.jsx b/src/components/JwtSection/JwtForm.jsx index f450f0ec..40e653ef 100644 --- a/src/components/JwtSection/JwtForm.jsx +++ b/src/components/JwtSection/JwtForm.jsx @@ -21,6 +21,7 @@ import IconButton from '@mui/material/IconButton'; import AddIcon from '@mui/icons-material/Add'; import CollectionAccessDialog from './CollectionAccessDialog'; import configureCollection from './RbacCollectionSettings'; +import TokenValidatior from './TokenValidatior'; const ExpirationSelect = ({ expiration, setExpiration }) => { const handleChange = (event) => { @@ -28,7 +29,7 @@ const ExpirationSelect = ({ expiration, setExpiration }) => { }; return ( - + Expiration { + setSelectedCollection(collections.find((collection) => collection.name === e.target.value)); + }} + > + + Not Selected + + {collections.map((collection) => ( + + {collection.name} + + ))} + + + + + + + Set Matches + + + {Object.keys(matches).map((key) => { + return ( + :not(:last-of-type)': { width: '40%' } }} key={key}> + + + { + const newMatches = { ...matches }; + delete newMatches[key]; + setMatches(newMatches); + }} + > + + + + ); + })} + :not(:last-of-type)': { width: '40%' } }}> + setNewMatchesKey(e.target.value)} /> + + setNewMatchesValue(e.target.value)} /> + { + setMatches((prev) => ({ + ...prev, + [newMatchesKey]: newMatchesValue, + })); + setNewMatchesKey(''); + setNewMatchesValue(''); + }} + disabled={!newMatchesKey || !newMatchesValue} + > + + + + + + + + + + + ); +}; + +TokenValidatior.propTypes = { + setTokenValidatior: PropTypes.func.isRequired, +}; + +export default TokenValidatior; diff --git a/src/pages/Jwt.jsx b/src/pages/Jwt.jsx index ff96a0e2..efa9d1da 100644 --- a/src/pages/Jwt.jsx +++ b/src/pages/Jwt.jsx @@ -13,7 +13,7 @@ async function getJwt(apiKey, token, setJwt) { setJwt(jwt); } -function generateToken(globalAccess, manageAccess, expirationDays, configuredCollections) { +function generateToken(globalAccess, manageAccess, expirationDays, configuredCollections, tokenValidatior) { const token = {}; if (globalAccess) { if (manageAccess) { @@ -30,6 +30,9 @@ function generateToken(globalAccess, manageAccess, expirationDays, configuredCol token.exp = Math.floor(Date.now() / 1000) + expirationDays * secondsInDay; } + if (tokenValidatior && tokenValidatior.collection && tokenValidatior.matches.length > 0) { + token.value_exists = tokenValidatior; + } return token; } @@ -46,11 +49,12 @@ function Jwt() { const [collections, setCollections] = useState([]); const [configuredCollections, setConfiguredCollections] = useState([]); + const [tokenValidatior, setTokenValidatior] = useState({}); const [apiKey, setApiKey] = useState(''); const [jwt, setJwt] = useState(''); - const token = generateToken(globalAccess, manageAccess, expirationDays, configuredCollections); + const token = generateToken(globalAccess, manageAccess, expirationDays, configuredCollections, tokenValidatior); useEffect(() => { if (apiKey && token) { @@ -104,6 +108,7 @@ function Jwt() { setManageAccess={setManageAccess} collections={configuredCollections} setCollections={setConfiguredCollections} + setTokenValidatior={setTokenValidatior} />