make auto redirect to idp a select input

This commit is contained in:
miloschwartz
2025-12-22 15:03:57 -05:00
parent 221ee6a1c2
commit 4da0a752ef
2 changed files with 50 additions and 101 deletions

View File

@@ -2349,6 +2349,7 @@
"enterConfirmation": "Enter confirmation", "enterConfirmation": "Enter confirmation",
"blueprintViewDetails": "Details", "blueprintViewDetails": "Details",
"defaultIdentityProvider": "Default Identity Provider", "defaultIdentityProvider": "Default Identity Provider",
"defaultIdentityProviderDescription": "When a default identity provider is selected, the user will be automatically redirected to the provider for authentication.",
"editInternalResourceDialogNetworkSettings": "Network Settings", "editInternalResourceDialogNetworkSettings": "Network Settings",
"editInternalResourceDialogAccessPolicy": "Access Policy", "editInternalResourceDialogAccessPolicy": "Access Policy",
"editInternalResourceDialogAddRoles": "Add Roles", "editInternalResourceDialogAddRoles": "Add Roles",

View File

@@ -16,7 +16,6 @@ import { SwitchInput } from "@app/components/SwitchInput";
import { Tag, TagInput } from "@app/components/tags/tag-input"; import { Tag, TagInput } from "@app/components/tags/tag-input";
import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert";
import { Button } from "@app/components/ui/button"; import { Button } from "@app/components/ui/button";
import { CheckboxWithLabel } from "@app/components/ui/checkbox";
import { import {
Form, Form,
FormControl, FormControl,
@@ -184,9 +183,6 @@ export default function ResourceAuthenticationPage() {
const [ssoEnabled, setSsoEnabled] = useState(resource.sso); const [ssoEnabled, setSsoEnabled] = useState(resource.sso);
const [autoLoginEnabled, setAutoLoginEnabled] = useState(
resource.skipToIdpId !== null && resource.skipToIdpId !== undefined
);
const [selectedIdpId, setSelectedIdpId] = useState<number | null>( const [selectedIdpId, setSelectedIdpId] = useState<number | null>(
resource.skipToIdpId || null resource.skipToIdpId || null
); );
@@ -243,17 +239,12 @@ export default function ResourceAuthenticationPage() {
text: w.email text: w.email
})) }))
); );
if (autoLoginEnabled && !selectedIdpId && orgIdps.length > 0) {
setSelectedIdpId(orgIdps[0].idpId);
}
hasInitializedRef.current = true; hasInitializedRef.current = true;
}, [ }, [
pageLoading, pageLoading,
resourceRoles, resourceRoles,
resourceUsers, resourceUsers,
whitelist, whitelist,
autoLoginEnabled,
selectedIdpId,
orgIdps orgIdps
]); ]);
@@ -269,16 +260,6 @@ export default function ResourceAuthenticationPage() {
const data = usersRolesForm.getValues(); const data = usersRolesForm.getValues();
try { try {
// Validate that an IDP is selected if auto login is enabled
if (autoLoginEnabled && !selectedIdpId) {
toast({
variant: "destructive",
title: t("error"),
description: t("selectIdpRequired")
});
return;
}
const jobs = [ const jobs = [
api.post(`/resource/${resource.resourceId}/roles`, { api.post(`/resource/${resource.resourceId}/roles`, {
roleIds: data.roles.map((i) => parseInt(i.id)) roleIds: data.roles.map((i) => parseInt(i.id))
@@ -288,7 +269,7 @@ export default function ResourceAuthenticationPage() {
}), }),
api.post(`/resource/${resource.resourceId}`, { api.post(`/resource/${resource.resourceId}`, {
sso: ssoEnabled, sso: ssoEnabled,
skipToIdpId: autoLoginEnabled ? selectedIdpId : null skipToIdpId: selectedIdpId
}) })
]; ];
@@ -296,7 +277,7 @@ export default function ResourceAuthenticationPage() {
updateResource({ updateResource({
sso: ssoEnabled, sso: ssoEnabled,
skipToIdpId: autoLoginEnabled ? selectedIdpId : null skipToIdpId: selectedIdpId
}); });
updateAuthInfo({ updateAuthInfo({
@@ -619,88 +600,55 @@ export default function ResourceAuthenticationPage() {
)} )}
{ssoEnabled && allIdps.length > 0 && ( {ssoEnabled && allIdps.length > 0 && (
<> <div className="space-y-2">
<div className="space-y-2 mb-3"> <label className="text-sm font-medium">
<CheckboxWithLabel {t(
label={t( "defaultIdentityProvider"
"autoLoginExternalIdp" )}
)} </label>
checked={autoLoginEnabled} <Select
onCheckedChange={( onValueChange={(value) => {
checked if (value === "none") {
) => { setSelectedIdpId(null);
setAutoLoginEnabled( } else {
checked as boolean setSelectedIdpId(
parseInt(value)
); );
if ( }
checked && }}
allIdps.length > 0 value={
) { selectedIdpId
setSelectedIdpId( ? selectedIdpId.toString()
allIdps[0].id : "none"
); }
} else { >
setSelectedIdpId( <SelectTrigger className="w-full mt-1">
null <SelectValue
); placeholder={t(
} "selectIdpPlaceholder"
}}
/>
<p className="text-sm text-muted-foreground">
{t(
"autoLoginExternalIdpDescription"
)}
</p>
</div>
{autoLoginEnabled && (
<div className="space-y-2">
<label className="text-sm font-medium">
{t(
"defaultIdentityProvider"
)} )}
</label> />
<Select </SelectTrigger>
onValueChange={( <SelectContent>
value <SelectItem value="none">
) => {t("none")}
setSelectedIdpId( </SelectItem>
parseInt(value) {allIdps.map((idp) => (
) <SelectItem
} key={idp.id}
value={ value={idp.id.toString()}
selectedIdpId >
? selectedIdpId.toString() {idp.text}
: undefined </SelectItem>
} ))}
> </SelectContent>
<SelectTrigger className="w-full mt-1"> </Select>
<SelectValue <p className="text-sm text-muted-foreground">
placeholder={t( {t(
"selectIdpPlaceholder" "defaultIdentityProviderDescription"
)} )}
/> </p>
</SelectTrigger> </div>
<SelectContent>
{allIdps.map(
(idp) => (
<SelectItem
key={
idp.id
}
value={idp.id.toString()}
>
{
idp.text
}
</SelectItem>
)
)}
</SelectContent>
</Select>
</div>
)}
</>
)} )}
</form> </form>
</Form> </Form>