Skip to content

Commit

Permalink
Add CORS support in the Zirku.Server sample
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnLErvin authored Dec 20, 2024
1 parent 7388e2d commit 6e1b9aa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 0 additions & 1 deletion samples/Hollastin/Hollastin.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddControllersWithViews();

services.AddDbContext<ApplicationDbContext>(options =>
Expand Down
1 change: 0 additions & 1 deletion samples/Imynusoph/Imynusoph.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public Startup(IConfiguration configuration)

public void ConfigureServices(IServiceCollection services)
{
services.AddCors();
services.AddControllersWithViews();

services.AddDbContext<ApplicationDbContext>(options =>
Expand Down
8 changes: 6 additions & 2 deletions samples/Zirku/Zirku.Api1/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
options.UseAspNetCore();
});

builder.Services.AddCors();
builder.Services.AddCors(options => options.AddDefaultPolicy(policy =>
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins("http://localhost:5112")));

builder.Services.AddAuthentication(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
builder.Services.AddAuthorization();

var app = builder.Build();

app.UseCors(b => b.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:5112"));
app.UseCors();
app.UseHttpsRedirection();

app.UseAuthentication();
Expand Down
6 changes: 6 additions & 0 deletions samples/Zirku/Zirku.Api2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@
options.UseAspNetCore();
});

builder.Services.AddCors(options => options.AddDefaultPolicy(policy =>
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins("http://localhost:5112")));

builder.Services.AddAuthentication(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
builder.Services.AddAuthorization();

var app = builder.Build();

app.UseCors();
app.UseHttpsRedirection();

app.UseAuthentication();
Expand Down
10 changes: 7 additions & 3 deletions samples/Zirku/Zirku.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@
options.UseAspNetCore();
});

builder.Services.AddCors();
builder.Services.AddCors(options => options.AddDefaultPolicy(policy =>
policy.AllowAnyHeader()
.AllowAnyMethod()
.WithOrigins("http://localhost:5112")));

builder.Services.AddAuthorization();

var app = builder.Build();

app.UseCors(b => b.AllowAnyHeader().AllowAnyMethod().WithOrigins("http://localhost:5112"));
app.UseCors();
app.UseHttpsRedirection();

// Create new application registrations matching the values configured in Zirku.Client1 and Zirku.Api1.
Expand Down Expand Up @@ -278,7 +282,7 @@ await manager.CreateAsync(new OpenIddictScopeDescriptor
identity.SetScopes(identifier switch
{
1 => request.GetScopes(),
2 => new[] { "api1" }.Intersect(request.GetScopes()),
2 => new[] { Scopes.OpenId, "api1" }.Intersect(request.GetScopes()),
_ => throw new InvalidOperationException()
});

Expand Down

0 comments on commit 6e1b9aa

Please sign in to comment.