diff --git a/src/Tingle.AspNetCore.Authorization/ApprovedIPNetworkRequirement.cs b/src/Tingle.AspNetCore.Authorization/ApprovedIPNetworkRequirement.cs
index f8398d9..9b95e65 100644
--- a/src/Tingle.AspNetCore.Authorization/ApprovedIPNetworkRequirement.cs
+++ b/src/Tingle.AspNetCore.Authorization/ApprovedIPNetworkRequirement.cs
@@ -7,7 +7,11 @@ namespace Tingle.AspNetCore.Authorization;
/// An that contains IP networks
///
/// the networks allowed
+#if NET8_0_OR_GREATER
public sealed class ApprovedIPNetworkRequirement(IList networks) : IAuthorizationRequirement
+#else
+public sealed class ApprovedIPNetworkRequirement(IList networks) : IAuthorizationRequirement
+#endif
{
///
/// Checks is an instance of is approved
diff --git a/src/Tingle.AspNetCore.Authorization/AuthorizationPolicyBuilderExtensions.cs b/src/Tingle.AspNetCore.Authorization/AuthorizationPolicyBuilderExtensions.cs
index 24614f6..09c07e7 100644
--- a/src/Tingle.AspNetCore.Authorization/AuthorizationPolicyBuilderExtensions.cs
+++ b/src/Tingle.AspNetCore.Authorization/AuthorizationPolicyBuilderExtensions.cs
@@ -19,15 +19,18 @@ public static class AuthorizationPolicyBuilderExtensions
///
/// The instance to add to
/// The allowed networks
- public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
- IList networks)
+#if NET8_0_OR_GREATER
+ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, IList networks)
+#else
+ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, IList networks)
+#endif
{
// if there are no networks just return
if (!networks.Any()) return builder;
// reduce the networks where possible (referred to as supernetting)
#if !NET8_0_OR_GREATER
- networks = IPNetwork.Supernet([.. networks]);
+ networks = IPNetwork2.Supernet([.. networks]);
#endif
// add the requirement
@@ -41,10 +44,13 @@ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this Authorizat
///
/// The instance to add to
/// The allowed networks
- public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
- params string[] networks)
+ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params string[] networks)
{
+#if NET8_0_OR_GREATER
var parsed = networks.Select(a => IPNetwork.Parse(a)).ToList();
+#else
+ var parsed = networks.Select(a => IPNetwork2.Parse(a)).ToList();
+#endif
return builder.RequireApprovedNetworks(parsed);
}
@@ -55,8 +61,11 @@ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this Authorizat
///
/// The instance to add to
/// The allowed networks
- public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder,
- params IPNetwork[] networks)
+#if NET8_0_OR_GREATER
+ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params IPNetwork[] networks)
+#else
+ public static AuthorizationPolicyBuilder RequireApprovedNetworks(this AuthorizationPolicyBuilder builder, params IPNetwork2[] networks)
+#endif
{
return builder.RequireApprovedNetworks(networks.ToList());
}
@@ -122,10 +131,13 @@ public static AuthorizationPolicyBuilder RequireAzureIPNetworks(this Authorizati
/// A list of Fully Qualified Domain Names.
/// Each of them will be resolved to list of IP addresses using
///
- public static AuthorizationPolicyBuilder RequireNetworkFromDns(this AuthorizationPolicyBuilder builder,
- params string[] fqdns)
+ public static AuthorizationPolicyBuilder RequireNetworkFromDns(this AuthorizationPolicyBuilder builder, params string[] fqdns)
{
+#if NET8_0_OR_GREATER
var networks = new List();
+#else
+ var networks = new List();
+#endif
// work on each FQDN
foreach (var f in fqdns)
@@ -136,7 +148,11 @@ public static AuthorizationPolicyBuilder RequireNetworkFromDns(this Authorizatio
var ips = Dns.GetHostAddresses(f);
// parse the IP addresses into IP networks
+#if NET8_0_OR_GREATER
var rawNetworks = ips?.Select(ip => new IPNetwork(ip, (byte)(ip.AddressFamily is AddressFamily.InterNetwork ? 32 : 128)));
+#else
+ var rawNetworks = ips?.Select(ip => new IPNetwork2(ip, (byte)(ip.AddressFamily is AddressFamily.InterNetwork ? 32 : 128)));
+#endif
// add networks into the list if there are any
if (rawNetworks?.Any() ?? false)
diff --git a/src/Tingle.AspNetCore.Authorization/Tingle.AspNetCore.Authorization.csproj b/src/Tingle.AspNetCore.Authorization/Tingle.AspNetCore.Authorization.csproj
index 4796d51..fdd681c 100644
--- a/src/Tingle.AspNetCore.Authorization/Tingle.AspNetCore.Authorization.csproj
+++ b/src/Tingle.AspNetCore.Authorization/Tingle.AspNetCore.Authorization.csproj
@@ -10,7 +10,7 @@
-
+