Commit bac49f42 authored by Eric Dieckman's avatar Eric Dieckman
Browse files

Add CORS

parent 9342a987
Loading
Loading
Loading
Loading
+16 −11
Original line number Diff line number Diff line
@@ -31,17 +31,20 @@ ConfigureAzureKeyVault(builder);
//            ValidateIssuer = true
//        };

//        options.Events = new JwtBearerEvents
//        {
//            OnTokenValidated = context =>
//            {
//                ClaimsIdentity identity = (ClaimsIdentity)context.Principal!.Identity!;
//                var token = context.SecurityToken.RawData;
//                identity.AddClaim(new Claim("access_token", token));
//                return Task.CompletedTask;
//            }
//        }
//    });
// Configure CORS policy
builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(policy =>
    {
        if (allowedOrigins?.Length > 0)
        {
            policy.WithOrigins(allowedOrigins)
                  .AllowAnyHeader()
                  .AllowAnyMethod()
                  .AllowCredentials();
        }
    });
});


builder.Services.AddControllers();
@@ -85,6 +88,8 @@ app.UseStaticFiles();
// AFTER UseStaticFiles, UseExceptionHandler or UseStatusCodePagesWithReExecute but BEFORE UseAuthentication and UseAuthorization
app.UseRouting();

app.UseCors();

app.UseAuthentication();
app.UseHttpsRedirection();