mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-10 01:59:03 +02:00
Change CORS policy
This commit is contained in:
parent
66ffa7ca73
commit
6e0780b15f
@ -1,10 +1,12 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using VoidCat.Model;
|
||||
using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Controllers.Admin;
|
||||
|
||||
[EnableCors(CorsPolicy.Auth)]
|
||||
[Route("admin")]
|
||||
[Authorize(Policy = Policies.RequireAdmin)]
|
||||
public class AdminController : Controller
|
||||
|
@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using VoidCat.Model;
|
||||
@ -9,6 +10,7 @@ using VoidCat.Services.Abstractions;
|
||||
|
||||
namespace VoidCat.Controllers;
|
||||
|
||||
[EnableCors(CorsPolicy.Auth)]
|
||||
[Route("auth")]
|
||||
public class AuthController : Controller
|
||||
{
|
||||
|
@ -13,6 +13,6 @@ public static class Policies
|
||||
|
||||
public static class CorsPolicy
|
||||
{
|
||||
public const string Default = "default";
|
||||
public const string Auth = "auth";
|
||||
public const string Upload = "upload";
|
||||
}
|
@ -35,7 +35,7 @@ if (useRedis)
|
||||
|
||||
services.AddCors(opt =>
|
||||
{
|
||||
opt.AddPolicy(CorsPolicy.Default, p =>
|
||||
opt.AddDefaultPolicy(p =>
|
||||
{
|
||||
p.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
@ -49,6 +49,14 @@ services.AddCors(opt =>
|
||||
.WithHeaders("V-Content-Type", "V-Filename", "V-Digest", "V-EditSecret", "Content-Type", "Authorization")
|
||||
.WithOrigins(voidSettings.CorsOrigins.Select(a => a.OriginalString).ToArray());
|
||||
});
|
||||
|
||||
opt.AddPolicy(CorsPolicy.Auth, p =>
|
||||
{
|
||||
p.AllowCredentials()
|
||||
.AllowAnyMethod()
|
||||
.WithHeaders("Authorization")
|
||||
.WithOrigins(voidSettings.CorsOrigins.Select(a => a.OriginalString).ToArray());
|
||||
});
|
||||
});
|
||||
|
||||
services.AddRouting();
|
||||
@ -130,7 +138,7 @@ app.UseStaticFiles();
|
||||
#endif
|
||||
|
||||
app.UseRouting();
|
||||
app.UseCors(CorsPolicy.Default);
|
||||
app.UseCors();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user