mirror of
https://github.com/D4M13N-D3V/art_platform.git
synced 2025-03-14 07:44:54 +00:00
added admin restrictions
This commit is contained in:
parent
85fade49b5
commit
65c7a720c4
@ -22,10 +22,19 @@
|
|||||||
<Content Include="..\.dockerignore">
|
<Content Include="..\.dockerignore">
|
||||||
<Link>.dockerignore</Link>
|
<Link>.dockerignore</Link>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Remove="react\public\favicon.ico" />
|
||||||
|
<None Remove="react\public\index.html" />
|
||||||
|
<None Remove="react\public\logo192.png" />
|
||||||
|
<None Remove="react\public\logo512.png" />
|
||||||
|
<None Remove="react\public\robots.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ArtPlatform.Database\ArtPlatform.Database.csproj" />
|
<ProjectReference Include="..\ArtPlatform.Database\ArtPlatform.Database.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="react\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
namespace ArtPlatform.API.Controllers;
|
namespace ArtPlatform.API.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize("admin")]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
public class AdminSellerProfileRequestsController : Controller
|
public class AdminSellerProfileRequestsController : Controller
|
||||||
{
|
{
|
||||||
|
@ -30,11 +30,17 @@ public class UserMiddleware
|
|||||||
Id = userId,
|
Id = userId,
|
||||||
DisplayName = context.User.Identity.Name ?? "Anonymous",
|
DisplayName = context.User.Identity.Name ?? "Anonymous",
|
||||||
Biography = string.Empty,
|
Biography = string.Empty,
|
||||||
Email = context.User.Claims.FirstOrDefault(x=>x.Type=="email")?.Value ?? string.Empty,
|
Email = context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Email)?.Value ?? string.Empty,
|
||||||
};
|
};
|
||||||
dbContext.Users.Add(user);
|
dbContext.Users.Add(user);
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user.Email= context.User.Claims.FirstOrDefault(x=>x.Type==ClaimTypes.Email)?.Value ?? string.Empty;
|
||||||
|
dbContext.Users.Update(user);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _next(context);
|
await _next(context);
|
||||||
|
@ -8,6 +8,7 @@ using ArtPlatform.Database;
|
|||||||
using Auth0.AspNetCore.Authentication;
|
using Auth0.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
@ -19,7 +20,6 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
builder.Services.AddSingleton<IStorageService,ImgCdnStorageServiceProvider>();
|
builder.Services.AddSingleton<IStorageService,ImgCdnStorageServiceProvider>();
|
||||||
builder.Services.AddSingleton<IPaymentService,StripePaymentServiceProvider>();
|
builder.Services.AddSingleton<IPaymentService,StripePaymentServiceProvider>();
|
||||||
|
|
||||||
|
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddDbContext<ApplicationDbContext>();
|
builder.Services.AddDbContext<ApplicationDbContext>();
|
||||||
@ -87,18 +87,21 @@ builder.Services.AddControllers()
|
|||||||
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles
|
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles
|
||||||
);
|
);
|
||||||
|
|
||||||
builder.Services.AddAuthentication(options =>
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
|
||||||
{
|
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
}).AddJwtBearer(options =>
|
|
||||||
{
|
{
|
||||||
options.Authority = $"{builder.Configuration.GetValue<string>("Auth0:Domain")}";
|
options.Authority = $"{builder.Configuration.GetValue<string>("Auth0:Domain")}";
|
||||||
options.Audience = $"{builder.Configuration.GetValue<string>("Auth0:Audience")}";
|
options.Audience = $"{builder.Configuration.GetValue<string>("Auth0:Audience")}";
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
NameClaimType = ClaimTypes.NameIdentifier,
|
||||||
|
RoleClaimType = ClaimTypes.Role
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Services.AddAuthorization(options =>
|
builder.Services.AddAuthorization(options =>
|
||||||
{
|
{
|
||||||
|
options.AddPolicy("admin", policy => policy.RequireClaim(ClaimTypes.Role, "Admin"));
|
||||||
|
|
||||||
options.AddPolicy("read:user", policy => policy.Requirements.Add(new
|
options.AddPolicy("read:user", policy => policy.Requirements.Add(new
|
||||||
HasScopeRequirement("read:user", builder.Configuration.GetValue<string>("Auth0:Domain"))));
|
HasScopeRequirement("read:user", builder.Configuration.GetValue<string>("Auth0:Domain"))));
|
||||||
options.AddPolicy("write:user", policy => policy.Requirements.Add(new
|
options.AddPolicy("write:user", policy => policy.Requirements.Add(new
|
||||||
@ -139,6 +142,7 @@ builder.Services.AddSingleton<IAuthorizationHandler, HasScopeHandler>();
|
|||||||
|
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(settings =>
|
app.UseSwaggerUI(settings =>
|
||||||
{
|
{
|
||||||
@ -147,9 +151,13 @@ app.UseSwaggerUI(settings =>
|
|||||||
settings.OAuthClientId(builder.Configuration.GetValue<string>("Auth0:ClientId"));
|
settings.OAuthClientId(builder.Configuration.GetValue<string>("Auth0:ClientId"));
|
||||||
settings.OAuthClientSecret(builder.Configuration.GetValue<string>("Auth0:ClientSecret"));
|
settings.OAuthClientSecret(builder.Configuration.GetValue<string>("Auth0:ClientSecret"));
|
||||||
settings.OAuthUsePkce();
|
settings.OAuthUsePkce();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
var defaultFilesOptions = new DefaultFilesOptions();
|
||||||
|
defaultFilesOptions.DefaultFileNames.Clear();
|
||||||
|
defaultFilesOptions.DefaultFileNames.Add("index.html"); // replace 'yourf
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseMiddleware<UserMiddleware>();
|
app.UseMiddleware<UserMiddleware>();
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "",
|
||||||
"applicationUrl": "http://localhost:5290",
|
"applicationUrl": "http://localhost:5290",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "",
|
||||||
"applicationUrl": "https://localhost:7148;http://localhost:5290",
|
"applicationUrl": "https://localhost:7148;http://localhost:5290",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Information",
|
"Default": "Trace",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Trace"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user