Skip to content

Commit

Permalink
CorsConfigExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-masse committed Mar 21, 2022
1 parent 9f8eb5e commit c117911
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions Nuages.Web/CorsConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -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();
});
});
}
}
2 changes: 1 addition & 1 deletion Nuages.Web/Nuages.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

</PropertyGroup>

<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.15.1" />
</ItemGroup>

Expand Down

0 comments on commit c117911

Please sign in to comment.