Ejemplo n.º 1
0
        public static bool IsExcluded(this IOpenIdConnectRequestOptions options, IOpenIdConnectRequest openIdConnectRequest)
        {
            var username = openIdConnectRequest.GetUsername();

            if (!string.IsNullOrEmpty(username) && options.ExcludedUsernameExpression != null &&
                options.ExcludedUsernameExpression.IsMatch(username))
            {
                return(true);
            }

            var tenant = openIdConnectRequest.GetTenant();

            if (!string.IsNullOrEmpty(tenant) && options.ExcludedTenantExpression != null &&
                options.ExcludedTenantExpression.IsMatch(tenant))
            {
                return(true);
            }

            var osVersion = openIdConnectRequest.GetOsVersion();

            if (!string.IsNullOrEmpty(osVersion) && options.ExcludedOsVersionExpression != null &&
                options.ExcludedOsVersionExpression.IsMatch(osVersion))
            {
                return(true);
            }

            var device = openIdConnectRequest.GetDevice();

            if (!string.IsNullOrEmpty(device?.DeviceType) && options.ExcludedDeviceExpression != null && options.ExcludedDeviceExpression.IsMatch(device.DeviceType))
            {
                return(true);
            }

            return(options.ExcludedSubnets.Any(excludedSubnet => excludedSubnet.Contains(openIdConnectRequest.GetRemoteIpAddress())));
        }
        public static bool IsExcluded(this RecaptchaValidationOptions recaptchaValidationOptions, IOwinContext owinContext, IOpenIdConnectRequest openIdConnectRequest)
        {
            var subnetExcluded = recaptchaValidationOptions.ExcludedSubnets.Any(excludedSubnet =>
            {
                var remoteClientIpAddress = owinContext.GetRemoteClientIpAddress();
                IPAddress ipAaddress;
                return(IPAddress.TryParse(remoteClientIpAddress, out ipAaddress) && excludedSubnet.Contains(ipAaddress));
            });

            if (subnetExcluded)
            {
                return(true);
            }

            if (openIdConnectRequest == null)
            {
                return(false);
            }

            var username = openIdConnectRequest.GetUsername();

            if (!string.IsNullOrEmpty(username) && recaptchaValidationOptions.ExcludedUsernameExpression != null &&
                recaptchaValidationOptions.ExcludedUsernameExpression.IsMatch(username))
            {
                return(true);
            }

            var tenant = openIdConnectRequest.GetTenant();

            if (!string.IsNullOrEmpty(tenant) && recaptchaValidationOptions.ExcludedTenantExpression != null &&
                recaptchaValidationOptions.ExcludedTenantExpression.IsMatch(tenant))
            {
                return(true);
            }

            var osVersion = openIdConnectRequest.GetOsVersion();

            if (!string.IsNullOrEmpty(osVersion) && recaptchaValidationOptions.ExcludedOsVersionExpression != null &&
                recaptchaValidationOptions.ExcludedOsVersionExpression.IsMatch(osVersion))
            {
                return(true);
            }

            return(false);
        }