diff --git a/Nuages.Web/CorsConfigExtensions.cs b/Nuages.Web/CorsConfigExtensions.cs new file mode 100644 index 0000000..db3d114 --- /dev/null +++ b/Nuages.Web/CorsConfigExtensions.cs @@ -0,0 +1,34 @@ +namespace Nuages.Web; + +public static class CorsConfigExtensions +{ + // ReSharper disable once MemberCanBePrivate.Global + public const string AllowSpecificOrigins = "AllowSpecificOrigins"; + private const string AllowAnyOrigins = "AllowAnyOrigins"; + + // ReSharper disable once UnusedMember.Global + public static void AddCors(this IServiceCollection services, string[] domains) + { + services.AddCors(options => + { + options.AddPolicy(AllowSpecificOrigins, + builder => + { + builder.WithOrigins(domains) + .AllowCredentials() + .AllowAnyMethod() + .AllowAnyHeader(); + }); + + + options.AddPolicy(AllowAnyOrigins, + builder => + { + builder.AllowCredentials() + .SetIsOriginAllowed(_ => true) + .AllowAnyMethod() + .AllowAnyHeader(); + }); + }); + } +} \ No newline at end of file diff --git a/Nuages.Web/Nuages.Web.csproj b/Nuages.Web/Nuages.Web.csproj index e1b3ac5..6ed3b4f 100644 --- a/Nuages.Web/Nuages.Web.csproj +++ b/Nuages.Web/Nuages.Web.csproj @@ -19,7 +19,7 @@ - +