ERP-node/frontend/components/admin/AuthenticationConfig.tsx

292 lines
9.8 KiB
TypeScript

"use client";
import React from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { AuthType } from "@/lib/api/externalRestApiConnection";
interface AuthenticationConfigProps {
authType: AuthType;
authConfig: any;
onAuthTypeChange: (type: AuthType) => void;
onAuthConfigChange: (config: any) => void;
}
export function AuthenticationConfig({
authType,
authConfig = {},
onAuthTypeChange,
onAuthConfigChange,
}: AuthenticationConfigProps) {
// 인증 설정 변경
const updateAuthConfig = (field: string, value: string) => {
onAuthConfigChange({
...authConfig,
[field]: value,
});
};
return (
<div className="space-y-4">
{/* 인증 타입 선택 */}
<div className="space-y-2">
<Label htmlFor="auth-type"> </Label>
<Select value={authType} onValueChange={(value) => onAuthTypeChange(value as AuthType)}>
<SelectTrigger id="auth-type">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="none"> </SelectItem>
<SelectItem value="api-key">API Key</SelectItem>
<SelectItem value="bearer">Bearer Token</SelectItem>
<SelectItem value="basic">Basic Auth</SelectItem>
<SelectItem value="oauth2">OAuth 2.0</SelectItem>
<SelectItem value="db-token">DB </SelectItem>
</SelectContent>
</Select>
</div>
{/* 인증 타입별 설정 필드 */}
{authType === "api-key" && (
<div className="space-y-4 rounded-md border bg-gray-50 p-4">
<h4 className="text-sm font-medium">API Key </h4>
{/* 키 위치 */}
<div className="space-y-2">
<Label htmlFor="key-location"> </Label>
<Select
value={authConfig.keyLocation || "header"}
onValueChange={(value) => updateAuthConfig("keyLocation", value)}
>
<SelectTrigger id="key-location">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="header">Header</SelectItem>
<SelectItem value="query">Query Parameter</SelectItem>
</SelectContent>
</Select>
</div>
{/* 키 이름 */}
<div className="space-y-2">
<Label htmlFor="key-name"> </Label>
<Input
id="key-name"
type="text"
value={authConfig.keyName || ""}
onChange={(e) => updateAuthConfig("keyName", e.target.value)}
placeholder="예: X-API-Key"
/>
</div>
{/* 키 값 */}
<div className="space-y-2">
<Label htmlFor="key-value"> </Label>
<Input
id="key-value"
type="password"
value={authConfig.keyValue || ""}
onChange={(e) => updateAuthConfig("keyValue", e.target.value)}
placeholder="API Key를 입력하세요"
/>
</div>
</div>
)}
{authType === "bearer" && (
<div className="space-y-4 rounded-md border bg-gray-50 p-4">
<h4 className="text-sm font-medium">Bearer Token </h4>
{/* 토큰 */}
<div className="space-y-2">
<Label htmlFor="token">Token</Label>
<Input
id="token"
type="password"
value={authConfig.token || ""}
onChange={(e) => updateAuthConfig("token", e.target.value)}
placeholder="Bearer Token을 입력하세요"
/>
</div>
<p className="text-xs text-gray-500">
* Authorization &quot;Bearer &#123;token&#125;&quot; .
</p>
</div>
)}
{authType === "basic" && (
<div className="space-y-4 rounded-md border bg-gray-50 p-4">
<h4 className="text-sm font-medium">Basic Auth </h4>
{/* 사용자명 */}
<div className="space-y-2">
<Label htmlFor="username"></Label>
<Input
id="username"
type="text"
value={authConfig.username || ""}
onChange={(e) => updateAuthConfig("username", e.target.value)}
placeholder="사용자명을 입력하세요"
/>
</div>
{/* 비밀번호 */}
<div className="space-y-2">
<Label htmlFor="password"></Label>
<Input
id="password"
type="password"
value={authConfig.password || ""}
onChange={(e) => updateAuthConfig("password", e.target.value)}
placeholder="비밀번호를 입력하세요"
/>
</div>
<p className="text-xs text-gray-500">* Authorization Base64 .</p>
</div>
)}
{authType === "oauth2" && (
<div className="space-y-4 rounded-md border bg-gray-50 p-4">
<h4 className="text-sm font-medium">OAuth 2.0 </h4>
{/* Client ID */}
<div className="space-y-2">
<Label htmlFor="client-id">Client ID</Label>
<Input
id="client-id"
type="text"
value={authConfig.clientId || ""}
onChange={(e) => updateAuthConfig("clientId", e.target.value)}
placeholder="Client ID를 입력하세요"
/>
</div>
{/* Client Secret */}
<div className="space-y-2">
<Label htmlFor="client-secret">Client Secret</Label>
<Input
id="client-secret"
type="password"
value={authConfig.clientSecret || ""}
onChange={(e) => updateAuthConfig("clientSecret", e.target.value)}
placeholder="Client Secret을 입력하세요"
/>
</div>
{/* Token URL */}
<div className="space-y-2">
<Label htmlFor="token-url">Token URL</Label>
<Input
id="token-url"
type="text"
value={authConfig.tokenUrl || ""}
onChange={(e) => updateAuthConfig("tokenUrl", e.target.value)}
placeholder="예: https://oauth.example.com/token"
/>
</div>
<p className="text-xs text-gray-500">* OAuth 2.0 Client Credentials Grant .</p>
</div>
)}
{authType === "db-token" && (
<div className="space-y-4 rounded-md border bg-gray-50 p-4">
<h4 className="text-sm font-medium">DB </h4>
<div className="space-y-2">
<Label htmlFor="db-table-name"></Label>
<Input
id="db-table-name"
type="text"
value={authConfig.dbTableName || ""}
onChange={(e) => updateAuthConfig("dbTableName", e.target.value)}
placeholder="예: auth_tokens"
/>
</div>
<div className="space-y-2">
<Label htmlFor="db-value-column"> </Label>
<Input
id="db-value-column"
type="text"
value={authConfig.dbValueColumn || ""}
onChange={(e) =>
updateAuthConfig("dbValueColumn", e.target.value)
}
placeholder="예: access_token"
/>
</div>
<div className="space-y-2">
<Label htmlFor="db-where-column"> </Label>
<Input
id="db-where-column"
type="text"
value={authConfig.dbWhereColumn || ""}
onChange={(e) =>
updateAuthConfig("dbWhereColumn", e.target.value)
}
placeholder="예: service_name"
/>
</div>
<div className="space-y-2">
<Label htmlFor="db-where-value"> </Label>
<Input
id="db-where-value"
type="text"
value={authConfig.dbWhereValue || ""}
onChange={(e) =>
updateAuthConfig("dbWhereValue", e.target.value)
}
placeholder="예: kakao"
/>
</div>
<div className="space-y-2">
<Label htmlFor="db-header-name"> ()</Label>
<Input
id="db-header-name"
type="text"
value={authConfig.dbHeaderName || ""}
onChange={(e) =>
updateAuthConfig("dbHeaderName", e.target.value)
}
placeholder="기본값: Authorization"
/>
</div>
<div className="space-y-2">
<Label htmlFor="db-header-template">
릿 (, &#123;&#123;value&#125;&#125; )
</Label>
<Input
id="db-header-template"
type="text"
value={authConfig.dbHeaderTemplate || ""}
onChange={(e) =>
updateAuthConfig("dbHeaderTemplate", e.target.value)
}
placeholder='기본값: "Bearer {{value}}"'
/>
</div>
<p className="text-xs text-gray-500">
company_code는 .
</p>
</div>
)}
{authType === "none" && (
<div className="rounded-md border border-dashed p-4 text-center text-sm text-gray-500">
API입니다.
</div>
)}
</div>
);
}