Skip to content

Commit

Permalink
fix: validate API secret field for other platform if the initial plat…
Browse files Browse the repository at this point in the history
…form is OKTA
  • Loading branch information
edalex-yinzi committed Dec 4, 2024
1 parent 580a42e commit 74fa84d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ const OidcSettings = ({
apiDetails,
onApiDetailsChange,
showValidationErrors,
serverHasConfiguration,
// OKTA platform doesn't have client secret field which means there is no secret configuration in the server.
serverHasConfiguration && initialIdpDetails.platform !== "OKTA",
);

const handleOnSave = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ const commonApiDetails = (
onChange: (key: string, value: unknown) => void,
showValidationErrors: boolean,
apiDetails: ApiDetails,
isConfigured: boolean,
isSecreteConfigured: boolean,
): Record<string, FieldRenderOptions> => {
const { platform, apiUrl, apiClientId } = apiDetails;
// apiClientSecret is not exist in OktaApiDetails.
Expand Down Expand Up @@ -353,17 +353,17 @@ const commonApiDetails = (
desc: apiClientSecretDesc,
required: true,
// Validation is not required for updating but required for the initial creation.
validate: isConfigured ? constTrue : isNonEmptyString,
validate: isSecreteConfigured ? constTrue : isNonEmptyString,
component: passwordTextFiled({
name: apiClientSecretLabel,
value: apiClientSecret,
disabled: false,
required: true,
onChange: (value) => onChange("apiClientSecret", value),
showValidationErrors,
validate: isConfigured ? constTrue : isNonEmptyString,
validate: isSecreteConfigured ? constTrue : isNonEmptyString,
errorMessage: missingValue,
placeholder: isConfigured ? passwordMask : undefined,
placeholder: isSecreteConfigured ? passwordMask : undefined,
}),
},
};
Expand Down Expand Up @@ -393,21 +393,21 @@ export const generatePlatform = (
* @param apiDetails The value of the platform specific details.
* @param apiDetailsOnChange Function to be called when a platform specific field is changed.
* @param showValidationErrors Whether to show validation errors for each field.
* @param isConfigured Whether the server already has the API details.
* @param isSecreteConfigured Whether the server already has the API secrete.
*/
export const generateApiDetails = (
apiDetails: ApiDetails,
apiDetailsOnChange: (key: string, value: unknown) => void,
showValidationErrors: boolean,
isConfigured: boolean,
isSecreteConfigured: boolean,
): Record<string, FieldRenderOptions> => {
const platform = apiDetails.platform;

const apiCommonFields = commonApiDetails(
apiDetailsOnChange,
showValidationErrors,
apiDetails,
isConfigured,
isSecreteConfigured,
);
const { apiUrl, apiClientId, apiClientSecret } = apiCommonFields;

Expand Down

0 comments on commit 74fa84d

Please sign in to comment.