public ValidateOptionsResult Validate(IFido2Configuration configuration, bool isDevEnvironment)
        {
            // Validate Fido2Url
            if (configuration.IsEnabled && !UriValidationHelper.IsValid(
                    nameof(configuration.PasswordlessPageUrl),
                    configuration.PasswordlessPageUrl, isDevEnvironment, out var error))
            {
                return(ValidateOptionsResult.Fail(error));
            }

            // Validate Origin
            if (configuration.IsEnabled && !UriValidationHelper.IsValid(
                    nameof(configuration.Origin),
                    configuration.Origin, isDevEnvironment, out var errorOrigin))
            {
                return(ValidateOptionsResult.Fail(errorOrigin));
            }

            // Validate RelyingPartyId
            if (configuration.IsEnabled && string.IsNullOrEmpty(configuration.RelyingPartyId))
            {
                return(ValidateOptionsResult.Fail($"{nameof(configuration.RelyingPartyId)} is required"));
            }

            // Validate UserName
            if (configuration.IsEnabled && string.IsNullOrEmpty(configuration.UserName))
            {
                return(ValidateOptionsResult.Fail($"{nameof(configuration.UserName)} is required"));
            }

            return(ValidateOptionsResult.Success);
        }
Exemple #2
0
 public void Validate(IMagicLinkConfiguration configuration)
 {
     if (!UriValidationHelper.IsValid($"MagicLink.{nameof(configuration.RedirectUrl)}",
                                      configuration.RedirectUrl, true, out var errMessage))
     {
         throw new InvalidOperationException(errMessage);
     }
 }
Exemple #3
0
        public ValidateOptionsResult ValidateInternal(IOwnIdCoreConfiguration options)
        {
            if (!UriValidationHelper.IsValid(nameof(options.CallbackUrl), options.CallbackUrl, options.IsDevEnvironment,
                                             out var callBackUrlValidationError))
            {
                return(ValidateOptionsResult.Fail(callBackUrlValidationError));
            }

            if (!UriValidationHelper.IsValid(nameof(options.OwnIdApplicationUrl), options.OwnIdApplicationUrl, options.IsDevEnvironment,
                                             out var ownIdAppUrlValidationError))
            {
                return(ValidateOptionsResult.Fail(ownIdAppUrlValidationError));
            }

            if (options.JwtSignCredentials == default)
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.JwtSignCredentials)} are required"));
            }

            if (string.IsNullOrWhiteSpace(options.DID) || string.IsNullOrWhiteSpace(options.Name))
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.DID)} and {nameof(options.Name)} are required"));
            }

            if (options.CacheExpirationTimeout == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.CacheExpirationTimeout)} can not be equal to 0"));
            }

            if (options.JwtExpirationTimeout == 0)
            {
                return(ValidateOptionsResult.Fail(
                           $"{nameof(options.JwtExpirationTimeout)} can not be equal to 0"));
            }

            if (string.IsNullOrWhiteSpace(options.TopDomain))
            {
                return(ValidateOptionsResult.Fail($"{nameof(options.TopDomain)} is required"));
            }

            // Validate Fido2 configuration
            var fido2Validator        = new Fido2ConfigurationValidator();
            var fido2ValidationResult = fido2Validator.Validate(options.Fido2, options.IsDevEnvironment);

            if (fido2ValidationResult.Failed)
            {
                return(fido2ValidationResult);
            }

            if (!options.Fido2.IsEnabled && options.Fido2FallbackBehavior == Fido2FallbackBehavior.Block)
            {
                return(ValidateOptionsResult.Fail(
                           $"FIDO2 is disabled, but '{nameof(options.Fido2FallbackBehavior)}' is set to '{nameof(Fido2FallbackBehavior.Block)}'"));
            }


            if (options.ProfileConfiguration != null)
            {
                return(options.ProfileConfiguration.Validate());
            }

            return(ValidateOptionsResult.Success);
        }