Add authentication and identity support using ASP.NET Core Identity
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using API.Database;
|
||||
using API.Models.Internal.User;
|
||||
using API.Repository.AgeGroup;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var webRoot = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..", "wwwroot"));
|
||||
@@ -14,6 +16,14 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
// Authentication
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddAuthentication().AddCookie(IdentityConstants.ApplicationScheme);
|
||||
|
||||
builder.Services.AddIdentityCore<User>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddApiEndpoints();
|
||||
|
||||
// Database
|
||||
var postgreConnection = builder.Configuration.GetConnectionString("PostgresConnection");
|
||||
if (!string.IsNullOrEmpty(postgreConnection))
|
||||
@@ -57,6 +67,9 @@ app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
// Map Auth Endpoints
|
||||
app.MapIdentityApi<User>();
|
||||
|
||||
app.MapControllers();
|
||||
// Frontend Fallback
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
Reference in New Issue
Block a user