24 lines
No EOL
1.1 KiB
C#
24 lines
No EOL
1.1 KiB
C#
using FluentValidation;
|
|
using IdentityShroud.Core.Contracts;
|
|
|
|
namespace IdentityShroud.Api;
|
|
|
|
public class ClientCreateRequestValidator : AbstractValidator<ClientCreateRequest>
|
|
{
|
|
// most of standard ascii minus the control characters and space
|
|
private const string ClientIdPattern = "^[a-zA-Z0-9_-]+";
|
|
|
|
private readonly string[] _allowedAlgorithms = [ "RS256", "ES256" ];
|
|
|
|
public ClientCreateRequestValidator()
|
|
{
|
|
RuleFor(e => e.ClientId).NotEmpty().MaximumLength(40).Matches(ClientIdPattern);
|
|
RuleFor(e => e.Name).MaximumLength(80);
|
|
RuleFor(e => e.Description).MaximumLength(2048);
|
|
RuleFor(e => e.SignatureAlgorithm)
|
|
.Must(v => v is null || _allowedAlgorithms.Contains(v))
|
|
.WithMessage($"SignatureAlgorithm must be one of {string.Join(", ", _allowedAlgorithms)} or null");
|
|
RuleFor(e => e.AllowClientCredentialsFlow).Must(v => v is not true).When(e => e.Confidential is not true);
|
|
RuleFor(e => e.GenerateSecret).Must(v => v is not true).When(e => e.Confidential is not true);
|
|
}
|
|
} |