Skip to content

Commit

Permalink
Added AllowedOrigins CORS Configuration setting (#217)
Browse files Browse the repository at this point in the history
* Added `AllowOrigins` setting

* Renamed to `AllowedOrigins`
  • Loading branch information
rmaffitsancsoft authored Jul 6, 2024
1 parent 6174845 commit e1b3993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/dotnet/HQ.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@
builder.Services.AddScoped<IAuthorizationHandler, ProjectStatusReportAuthorizationHandler>();
builder.Services.AddScoped<IAuthorizationHandler, TimeEntryAuthorizationHandler>();

builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAny", policy => policy.AllowAnyHeader().AllowAnyOrigin().WithExposedHeaders("Content-Disposition")); // TODO: Replace with explicit allow URLs
});
builder.Services.AddCors();

builder.Services.AddControllersWithViews(options =>
{
Expand Down Expand Up @@ -216,7 +213,12 @@

app.UseHttpsRedirection();

app.UseCors("AllowAny");
var corsAllowOrigin = app.Configuration.GetSection("AllowedOrigins").Get<string[]>() ?? [];
app.UseCors(policy => policy
.WithOrigins(corsAllowOrigin)
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Content-Disposition"));

app.UseAuthentication();
app.UseAuthorization();
Expand Down
1 change: 1 addition & 0 deletions src/dotnet/HQ.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"From": "",
"FromDisplayName": "HQ"
},
"AllowedOrigins": ["http://localhost:4200", "http://hq.localhost:4200"],
"ForwardedHeadersOptions": {
"ForwardedHeaders": "XForwardedFor,XForwardedProto",
"KnownProxies": [
Expand Down

0 comments on commit e1b3993

Please sign in to comment.