| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- namespace Infrastructure.Kyc.Nice;
- /// <summary>
- /// NICE 통합인증 API 설정. appsettings.{env}.json 의 "Nice:Auth" 섹션 + Secret File 로 주입.
- ///
- /// ClientId / ClientSecret 가 비어 있으면 <see cref="NiceAuthClient"/> 가
- /// "Nice.NotConfigured" 에러를 반환. dev 환경에서 vendor 미연동 상태로 진행 가능 (Developers:SkipKyc=true 와 짝).
- /// </summary>
- public sealed class NiceAuthOptions
- {
- /// <summary>NICE API base URL. 예: https://svc.niceapi.co.kr:22001</summary>
- public string BaseUrl { get; set; } = string.Empty;
- /// <summary>NICE 발급 client_id.</summary>
- public string ClientId { get; set; } = string.Empty;
- /// <summary>NICE 발급 client_secret. Secret File 에만 보관.</summary>
- public string ClientSecret { get; set; } = string.Empty;
- /// <summary>NICE 발급 사이트코드 (SITECODE). 휴대폰 본인확인 신청서 식별자. 일부 보조 API 에 필요.</summary>
- public string SiteCode { get; set; } = string.Empty;
- /// <summary>
- /// 인증 후 NICE → 가맹점 callback URL 의 base 부분 (sessionToken 은 Backend 가 path segment 로 append).
- /// 예: https://api.dpot.live/api/developers/profile/kyc/callback
- /// </summary>
- public string ReturnUrl { get; set; } = string.Empty;
- /// <summary>표준창 닫기 버튼 클릭 시 이동 URL (Frontend 의 onboarding/kyc 페이지 권장).</summary>
- public string CloseUrl { get; set; } = string.Empty;
- /// <summary>
- /// Backend callback 결과를 사용자에게 보여줄 Frontend 페이지 URL.
- /// 예: https://developers.dpot.live/onboarding/kyc/callback
- /// (Backend 가 ?ok=1 또는 ?ok=0&message=... 으로 query 추가해 302 redirect)
- /// </summary>
- public string FrontendCallbackUrl { get; set; } = string.Empty;
- /// <summary>기본 인증수단. "M" 휴대폰 / "F" 금융인증서 / "U" 공동인증서 / "I" 아이핀.</summary>
- public string[] DefaultSvcTypes { get; set; } = ["M"];
- /// <summary>표준창 method_type. 기본 "GET" (가이드에 POST field 명세 없어 안전 선택).</summary>
- public string MethodType { get; set; } = "GET";
- /// <summary>Redis 토큰 캐시 키 prefix. e.g. "Nice:Auth:Token"</summary>
- public string TokenCacheKeyPrefix { get; set; } = "Nice:Auth:Token";
- /// <summary>토큰 캐시 TTL (초). NICE 토큰이 24h 라 safety margin 1h 빼고 23h = 82800 권장.</summary>
- public int TokenCacheTtlSeconds { get; set; } = 82800;
- /// <summary>HTTP 호출 timeout (초).</summary>
- public int HttpTimeoutSeconds { get; set; } = 15;
- /// <summary>Secret File 미주입 시 배포 config 에 남는 미치환 placeholder 접두사.</summary>
- private const string PlaceholderPrefix = "__INJECT_";
- /// <summary>
- /// 설정 완료(=vendor 연동 가능) 여부. BaseUrl/ClientId/ClientSecret 가 모두 채워져야 함.
- /// Secret File 미주입으로 남은 미치환 placeholder(__INJECT_...) 는 미설정으로 간주 —
- /// NICE 에 가짜 client_id 를 보내 "권한 오류(1006)" 가 나는 대신 "준비 중(NotConfigured)" 으로 안전 처리.
- /// </summary>
- public bool IsConfigured =>
- !string.IsNullOrWhiteSpace(BaseUrl) &&
- !string.IsNullOrWhiteSpace(ClientId) &&
- !string.IsNullOrWhiteSpace(ClientSecret) &&
- !ClientId.StartsWith(PlaceholderPrefix, StringComparison.Ordinal) &&
- !ClientSecret.StartsWith(PlaceholderPrefix, StringComparison.Ordinal);
- /// <summary>
- /// 배포 config 에 치환 안 된 placeholder(__INJECT_...) 가 남아있는지.
- /// true 면 "설정한 듯 보이나 실제론 미주입" 상태 → 부팅 시 운영자 경고 대상.
- /// </summary>
- public bool HasUnsubstitutedPlaceholder =>
- ClientId.StartsWith(PlaceholderPrefix, StringComparison.Ordinal) ||
- ClientSecret.StartsWith(PlaceholderPrefix, StringComparison.Ordinal);
- }
|