사용자 검증기 구조 분리: 내부(Family) / 외부(Extra) 검증 구분

- IUserValidator.Validate: bool 반환 → void (인증 실패 시 예외로 처리)
- BaronSSOOption: Validator → ExtraUserValidator로 명명, FamilyValidator(기본 DefaultFamilyUserValidator) 추가
- DefaultFamilyUserValidator 신규: Center/Family 테넌트 사용자 통과, 그 외 InvalidUserException
- BaronSSO.SignInAsync: Family/Extra 검증기 적용 흐름 정리
- InvalidUserException: UserInfo 기반 생성자
- Sample(MainWindow/SampleSettings/SimpleUserValidator) 갱신

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-16 14:54:21 +09:00
parent 1c41230021
commit a15cab4bc9
9 changed files with 103 additions and 58 deletions

View File

@@ -1,5 +1,3 @@
using BaronSoftware.SSO.Exceptions;
namespace BaronSoftware.SSO
{
/// <summary>
@@ -36,37 +34,45 @@ namespace BaronSoftware.SSO
}
/// <summary>웹뷰 로그인 창을 띄워 인증합니다.</summary>
public async Task SignInAsync() => await SignInAsync(null);
public async Task SignInAsync()
{
UserInfo? user = null;
if (option.EnableAutoLogin)
user = UserInfo.FromSsoFile();
await SignInAsync(user?.RefreshToken);
}
/// <summary>웹뷰 로그인 창을 띄워 인증합니다.</summary>
public async Task SignInAsync(string refreshToken)
{
UserInfo user = null;
if(option.EnableAutoLogin)
user = UserInfo.FromSsoFile();
var isConnected = await CheckConnection();
if(!isConnected && option.EnableOffline)
if (isConnected)
{
var token = await client.LoginAsync(refreshToken);
var userJson = await client.GetUserInfoAsync(token.AccessToken);
if (string.IsNullOrEmpty(userJson))
throw new InvalidOperationException($"Failed to get userinfo : {token.ToString()}");
user = UserInfo.FromJson(userJson, token);
if (user == null)
throw new InvalidUserException("Not found authorized last user.");
option?.Validator?.Validate(user);
return;
throw new InvalidUserException($"Broken user token. Token {token.ToString()}, UserJson {userJson}");
}
else
{
if (!option.EnableOffline)
throw new InvalidOperationException("Network isn't available.");
user = UserInfo.FromSsoFile();
if (user == null)
throw new InvalidUserException("Not found sso data for offline.");
}
var token = await client.LoginAsync(refreshToken);
var userJson = await client.GetUserInfoAsync(token.AccessToken);
if (string.IsNullOrEmpty(userJson))
throw new InvalidOperationException($"Failed to get userinfo : {token.ToString()}");
user = UserInfo.FromJson(userJson, token);
if (user == null || option?.Validator == null)
throw new NullReferenceException("user or validator option is null");
// 가족사가 아니고, 인증도 실패 시
if(!user.IsFamily()&& !option.Validator.Validate(user))
throw new InvalidUserException("Failed to authorize user");
if (user.IsFamily())
option?.FamilyValidator?.Validate(user);
else
option?.ExtraUserValidator?.Validate(user);
CurrentUser = user;
CurrentUser.Save();