- 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>
80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using BaronSoftware;
|
|
using BaronSoftware.Auth;
|
|
using BaronSoftware.SSO;
|
|
using BaronSoftware.SSO.Sample;
|
|
using System;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace BaronSoftware.Auth.Sample
|
|
{
|
|
/// <summary>
|
|
/// 실행 파일과 같은 폴더의 appsettings.json에서 접속 정보를 읽는다.
|
|
/// 파일이 없으면 내장 기본값을 사용하고, JSON 형식 오류는 예외로 알린다.
|
|
/// </summary>
|
|
public sealed class SampleSettings
|
|
{
|
|
public const string FileName = "appsettings.json";
|
|
|
|
public OidcSection Oidc { get; set; } = new();
|
|
|
|
public sealed class OidcSection
|
|
{
|
|
public string Authority { get; set; }
|
|
public string ClientId { get; set; }
|
|
public string RedirectUri { get; set; }
|
|
public string LogoutUri { get; set; }
|
|
public string Scope { get; set; }
|
|
}
|
|
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
ReadCommentHandling = JsonCommentHandling.Skip,
|
|
AllowTrailingCommas = true,
|
|
};
|
|
|
|
/// <summary>실행 파일 옆 appsettings.json을 로드. 파일이 없으면 기본값.</summary>
|
|
public static SampleSettings Load()
|
|
{
|
|
var path = Path.Combine(AppContext.BaseDirectory, FileName);
|
|
if (!File.Exists(path))
|
|
return new SampleSettings();
|
|
|
|
try
|
|
{
|
|
var json = File.ReadAllText(path);
|
|
return JsonSerializer.Deserialize<SampleSettings>(json, JsonOptions) ?? new SampleSettings();
|
|
}
|
|
catch (JsonException ex)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"설정 파일({FileName}) 형식 오류: {ex.Message}", ex);
|
|
}
|
|
}
|
|
|
|
|
|
private static readonly JsonSerializerOptions SaveOptions = new()
|
|
{
|
|
WriteIndented = true,
|
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
|
};
|
|
|
|
/// <summary>현재 설정을 실행 파일 옆 appsettings.json에 저장한다.</summary>
|
|
public void Save()
|
|
{
|
|
var path = Path.Combine(AppContext.BaseDirectory, FileName);
|
|
File.WriteAllText(path, JsonSerializer.Serialize(this, SaveOptions));
|
|
}
|
|
|
|
public BaronSSOOption ToOidcOptions() => new()
|
|
{
|
|
Authority = Oidc.Authority,
|
|
ClientId = Oidc.ClientId,
|
|
RedirectUri = Oidc.RedirectUri,
|
|
ExtraUserValidator = new SimpleUserValidator()
|
|
};
|
|
}
|
|
}
|