| 1 | namespace AgentForge.Abstractions; |
| 2 | |
| 3 | /// <summary>Login-page OAuth provider button owned by an oauth-* plugin (FORGE-ADR-0015 family pattern).</summary> |
| 4 | public sealed class ForgeOAuthLoginContributor |
| 5 | { |
| 6 | public required string ProviderId { get; init; } |
| 7 | |
| 8 | public required string PluginId { get; init; } |
| 9 | |
| 10 | public int Order { get; init; } = 100; |
| 11 | |
| 12 | /// <summary>Renders provider sign-in control HTML (icon button, link, etc.).</summary> |
| 13 | public required Func<string, string> RenderSignInControl { get; init; } |
| 14 | } |
| 15 | |
| 16 | public sealed class ForgeOAuthLoginContributorRegistry |
| 17 | { |
| 18 | private readonly List<ForgeOAuthLoginContributor> _contributors = []; |
| 19 | private readonly HashSet<string> _providerIds = new(StringComparer.OrdinalIgnoreCase); |
| 20 | |
| 21 | public IReadOnlyList<ForgeOAuthLoginContributor> Contributors => _contributors; |
| 22 | |
| 23 | public void Add(ForgeOAuthLoginContributor contributor) |
| 24 | { |
| 25 | ArgumentNullException.ThrowIfNull(contributor); |
| 26 | if (string.IsNullOrWhiteSpace(contributor.ProviderId)) |
| 27 | throw new ArgumentException("ProviderId is required.", nameof(contributor)); |
| 28 | if (contributor.RenderSignInControl is null) |
| 29 | throw new ArgumentException("RenderSignInControl is required.", nameof(contributor)); |
| 30 | |
| 31 | if (!_providerIds.Add(contributor.ProviderId.Trim())) |
| 32 | { |
| 33 | throw new InvalidOperationException( |
| 34 | $"Duplicate OAuth login provider '{contributor.ProviderId}' in plugin registration."); |
| 35 | } |
| 36 | |
| 37 | _contributors.Add(contributor); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | public interface IForgeOAuthLoginContributorCatalog |
| 42 | { |
| 43 | IReadOnlyList<ForgeOAuthLoginContributor> Contributors { get; } |
| 44 | } |
| 45 | |