Skip to content

Commit 23e5328

Browse files
authored
Merge pull request #124 from anik-ghosh-au7/feat/jwt-types
support for more jwt encryption types added
2 parents 5572928 + 47acff0 commit 23e5328

File tree

4 files changed

+96
-43
lines changed

4 files changed

+96
-43
lines changed

dashboard/src/components/InputField.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,17 +259,6 @@ const InputField = ({
259259
);
260260
}
261261
if (Object.values(SelectInputType).includes(inputType)) {
262-
if (inputType === SelectInputType.JWT_TYPE) {
263-
return (
264-
<Select size="sm" {...props}>
265-
{[variables[inputType]].map((value: string) => (
266-
<option value="value" key={value}>
267-
{value}
268-
</option>
269-
))}
270-
</Select>
271-
);
272-
}
273262
const { options, ...rest } = props;
274263
return (
275264
<Select
@@ -293,10 +282,18 @@ const InputField = ({
293282
<Textarea
294283
{...props}
295284
size="lg"
296-
value={inputData[inputType]}
297-
onChange={(e: any) => {
298-
setInputData({ ...inputData, [inputType]: e.target.value });
299-
}}
285+
fontSize={14}
286+
value={variables[inputType] ? variables[inputType] : ''}
287+
onChange={(
288+
event: Event & {
289+
target: HTMLInputElement;
290+
}
291+
) =>
292+
setVariables({
293+
...variables,
294+
[inputType]: event.target.value,
295+
})
296+
}
300297
/>
301298
);
302299
}

dashboard/src/constants.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const SelectInputType = {
4949

5050
export const TextAreaInputType = {
5151
CUSTOM_ACCESS_TOKEN_SCRIPT: 'CUSTOM_ACCESS_TOKEN_SCRIPT',
52+
JWT_PRIVATE_KEY: 'JWT_PRIVATE_KEY',
53+
JWT_PUBLIC_KEY: 'JWT_PUBLIC_KEY',
5254
};
5355

5456
export const SwitchInputType = {
@@ -66,3 +68,21 @@ export const ArrayInputOperations = {
6668
APPEND: 'APPEND',
6769
REMOVE: 'REMOVE',
6870
};
71+
72+
export const HMACEncryptionType = {
73+
HS256: 'HS256',
74+
HS384: 'HS384',
75+
HS512: 'HS512',
76+
};
77+
78+
export const RSAEncryptionType = {
79+
RS256: 'RS256',
80+
RS384: 'RS384',
81+
RS512: 'RS512',
82+
};
83+
84+
export const ECDSAEncryptionType = {
85+
ES256: 'ES256',
86+
ES384: 'ES384',
87+
ES512: 'ES512',
88+
};

dashboard/src/graphql/queries/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const EnvVariablesQuery = `
2121
JWT_TYPE,
2222
JWT_SECRET,
2323
JWT_ROLE_CLAIM,
24+
JWT_PRIVATE_KEY,
25+
JWT_PUBLIC_KEY,
2426
REDIS_URL,
2527
SMTP_HOST,
2628
SMTP_PORT,

dashboard/src/pages/Environment.tsx

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import {
3131
TextInputType,
3232
TextAreaInputType,
3333
SwitchInputType,
34+
HMACEncryptionType,
35+
RSAEncryptionType,
36+
ECDSAEncryptionType,
3437
} from '../constants';
3538
import { UpdateEnvVariables } from '../graphql/mutation';
3639
import { getObjectDiff, capitalizeFirstLetter } from '../utils';
@@ -48,6 +51,8 @@ interface envVarTypes {
4851
JWT_TYPE: string;
4952
JWT_SECRET: string;
5053
JWT_ROLE_CLAIM: string;
54+
JWT_PRIVATE_KEY: string;
55+
JWT_PUBLIC_KEY: string;
5156
REDIS_URL: string;
5257
SMTP_HOST: string;
5358
SMTP_PORT: string;
@@ -92,6 +97,8 @@ export default function Environment() {
9297
JWT_TYPE: '',
9398
JWT_SECRET: '',
9499
JWT_ROLE_CLAIM: '',
100+
JWT_PRIVATE_KEY: '',
101+
JWT_PUBLIC_KEY: '',
95102
REDIS_URL: '',
96103
SMTP_HOST: '',
97104
SMTP_PORT: '',
@@ -177,7 +184,6 @@ export default function Environment() {
177184
const {
178185
data: { _env: envData },
179186
} = await client.query(EnvVariablesQuery).toPromise();
180-
181187
const diff = getObjectDiff(envVariables, envData);
182188
const updatedEnvVariables = diff.reduce(
183189
(acc: any, property: string) => ({
@@ -374,39 +380,67 @@ export default function Environment() {
374380
<Flex w="30%" justifyContent="start" alignItems="center">
375381
<Text fontSize="sm">JWT Type:</Text>
376382
</Flex>
377-
<Center w="70%">
378-
<Flex w="100%" justifyContent="space-between">
379-
<Flex flex="2">
383+
<Flex w="70%">
384+
<InputField
385+
variables={envVariables}
386+
setVariables={setEnvVariables}
387+
inputType={SelectInputType.JWT_TYPE}
388+
value={SelectInputType.JWT_TYPE}
389+
options={{
390+
...HMACEncryptionType,
391+
...RSAEncryptionType,
392+
...ECDSAEncryptionType,
393+
}}
394+
/>
395+
</Flex>
396+
</Flex>
397+
{Object.values(HMACEncryptionType).includes(envVariables.JWT_TYPE) ? (
398+
<Flex>
399+
<Flex w="30%" justifyContent="start" alignItems="center">
400+
<Text fontSize="sm">JWT Secret</Text>
401+
</Flex>
402+
<Center w="70%">
403+
<InputField
404+
variables={envVariables}
405+
setVariables={setEnvVariables}
406+
fieldVisibility={fieldVisibility}
407+
setFieldVisibility={setFieldVisibility}
408+
inputType={HiddenInputType.JWT_SECRET}
409+
/>
410+
</Center>
411+
</Flex>
412+
) : (
413+
<>
414+
<Flex>
415+
<Flex w="30%" justifyContent="start" alignItems="center">
416+
<Text fontSize="sm">Public Key</Text>
417+
</Flex>
418+
<Center w="70%">
380419
<InputField
381420
variables={envVariables}
382421
setVariables={setEnvVariables}
383-
inputType={SelectInputType.JWT_TYPE}
384-
isDisabled={true}
385-
defaultValue={SelectInputType.JWT_TYPE}
422+
inputType={TextAreaInputType.JWT_PUBLIC_KEY}
423+
placeholder="Add public key here"
424+
minH="25vh"
386425
/>
426+
</Center>
427+
</Flex>
428+
<Flex>
429+
<Flex w="30%" justifyContent="start" alignItems="center">
430+
<Text fontSize="sm">Private Key</Text>
387431
</Flex>
388-
<Flex flex="3" justifyContent="center" alignItems="center">
389-
<Text fontSize="sm">
390-
More JWT types will be enabled in upcoming releases.
391-
</Text>
392-
</Flex>
432+
<Center w="70%">
433+
<InputField
434+
variables={envVariables}
435+
setVariables={setEnvVariables}
436+
inputType={TextAreaInputType.JWT_PRIVATE_KEY}
437+
placeholder="Add private key here"
438+
minH="25vh"
439+
/>
440+
</Center>
393441
</Flex>
394-
</Center>
395-
</Flex>
396-
<Flex>
397-
<Flex w="30%" justifyContent="start" alignItems="center">
398-
<Text fontSize="sm">JWT Secret</Text>
399-
</Flex>
400-
<Center w="70%">
401-
<InputField
402-
variables={envVariables}
403-
setVariables={setEnvVariables}
404-
fieldVisibility={fieldVisibility}
405-
setFieldVisibility={setFieldVisibility}
406-
inputType={HiddenInputType.JWT_SECRET}
407-
/>
408-
</Center>
409-
</Flex>
442+
</>
443+
)}
410444
<Flex>
411445
<Flex w="30%" justifyContent="start" alignItems="center">
412446
<Text fontSize="sm">JWT Role Claim:</Text>

0 commit comments

Comments
 (0)