diff --git a/DTO/UserDTO.cs b/DTO/UserDTO.cs new file mode 100644 index 0000000..f78d9a6 --- /dev/null +++ b/DTO/UserDTO.cs @@ -0,0 +1,8 @@ +namespace backend.DTO; + +public class UserDTO +{ + public string UserName { get; set; } + public string? Email { get; set; } + public string Password { get; set; } +} diff --git a/Models/UserIdentity.cs b/Models/UserIdentity.cs new file mode 100644 index 0000000..a9501eb --- /dev/null +++ b/Models/UserIdentity.cs @@ -0,0 +1,14 @@ +using MongoDB.Bson.Serialization.Attributes; + +namespace backend.Models; + +public class UserIdentity +{ + [BsonId] + [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)] + public string Id { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + public string Email { get; set; } + public string Role { get; set; } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index db12bd5..8eea6e6 100644 --- a/Program.cs +++ b/Program.cs @@ -1,5 +1,8 @@ +using System.Text; using backend.Models; using backend.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; var builder = WebApplication.CreateBuilder(args); @@ -7,7 +10,10 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.Configure(builder.Configuration.GetSection("BlogDatabase")); +//Authentication +builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(); builder.Services.AddSingleton(); + builder.Services.AddControllers(); @@ -22,13 +28,14 @@ if (app.Environment.IsDevelopment()) { app.UseStaticFiles(); app.UseSwagger(); - app.UseSwaggerUI(c=> c.InjectStylesheet("/swagger-ui/darkMode.css")); + app.UseSwaggerUI(c => c.InjectStylesheet("/swagger-ui/darkMode.css")); } app.UseHttpsRedirection(); +app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); -app.Run(); +app.Run(); \ No newline at end of file diff --git a/backend.csproj b/backend.csproj index 11f9191..dd964a1 100644 --- a/backend.csproj +++ b/backend.csproj @@ -7,8 +7,10 @@ + +