From 00b8b0de62f2a78963f233e061765b9ca0098bad Mon Sep 17 00:00:00 2001 From: RondineleG Date: Sat, 16 Sep 2023 21:31:51 -0300 Subject: [PATCH] feat : Codecleanup --- .../Configuration/ApiConfig.cs | 30 +- .../Configuration/IdentityConfig.cs | 28 +- .../Configuration/SwaggerConfig.cs | 32 +- .../Controllers/AuthController.cs | 28 +- .../Controllers/Base/MainController.cs | 105 ++-- .../Data/BrowlAuthSecurityDbContext.cs | 32 +- .../Data/ContextSeed.cs | 65 ++- .../Entities/AppSettings.cs | 15 +- .../Entities/ManageUserRoles.cs | 16 +- .../Entities/User.cs | 18 +- .../Entities/UserClaim.cs | 6 +- .../Entities/UserLogin.cs | 6 +- .../Entities/UserRegister.cs | 42 +- .../Entities/UserResponse.cs | 6 +- .../Entities/UserRoles.cs | 24 +- .../Entities/UserToken.cs | 8 +- .../Enums/Roles.cs | 15 +- .../20230916004956_InicialCreate.cs | 502 +++++++++--------- .../Browl.Service.AuthSecurity.API/Program.cs | 21 +- 19 files changed, 477 insertions(+), 522 deletions(-) diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/ApiConfig.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/ApiConfig.cs index 0bb9f7d..edac976 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/ApiConfig.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/ApiConfig.cs @@ -1,27 +1,21 @@ -using Browl.Service.AuthSecurity.API.Data; -using Browl.Service.AuthSecurity.Domain.Entities; - -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; - -namespace Browl.Service.AuthSecurity.API.Configuration; +namespace Browl.Service.AuthSecurity.API.Configuration; public static class ApiConfig { public static IServiceCollection AddApiConfiguration(this IServiceCollection services, IWebHostEnvironment hostEnvironment, IConfiguration configuration) { - services.AddControllers(); - services.AddEndpointsApiExplorer(); + _ = services.AddControllers(); + _ = services.AddEndpointsApiExplorer(); - IConfigurationBuilder builder = new ConfigurationBuilder() + var builder = new ConfigurationBuilder() .SetBasePath(hostEnvironment.ContentRootPath) .AddJsonFile("appsettings.json", true, true) .AddJsonFile($"appsettings.{hostEnvironment.EnvironmentName}.json", true, true) .AddEnvironmentVariables(); - + if (hostEnvironment.IsDevelopment()) { - builder.AddUserSecrets(); + _ = builder.AddUserSecrets(); } return services; @@ -39,16 +33,16 @@ public static IApplicationBuilder UseApiConfiguration(this IApplicationBuilder a // }); //} - app.UseHttpsRedirection(); + var unused5 = app.UseHttpsRedirection(); - app.UseRouting(); + var unused4 = app.UseRouting(); - app.UseAuthentication(); - app.UseAuthorization(); + var unused3 = app.UseAuthentication(); + var unused2 = app.UseAuthorization(); - app.UseEndpoints(endpoints => + var unused1 = app.UseEndpoints(endpoints => { - endpoints.MapControllers(); + var unused = endpoints.MapControllers(); }); return app; diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/IdentityConfig.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/IdentityConfig.cs index b970b68..0be7d64 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/IdentityConfig.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/IdentityConfig.cs @@ -1,4 +1,6 @@ -using Browl.Service.AuthSecurity.API.Data; +using System.Text; + +using Browl.Service.AuthSecurity.API.Data; using Browl.Service.AuthSecurity.API.Entities; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -6,8 +8,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; -using System.Text; - namespace Browl.Service.AuthSecurity.API.Configuration; public static class IdentityConfig @@ -15,23 +15,23 @@ public static class IdentityConfig public static IServiceCollection AddIdentityConfiguration(this IServiceCollection services, IConfiguration configuration) { - services.AddDbContext(options => + var unused3 = services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); - - services.AddDefaultIdentity() - .AddRoles() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); + + var unused2 = services.AddDefaultIdentity() + .AddRoles() + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); // JWT var appSettingsSection = configuration.GetSection("AppSettings"); - services.Configure(appSettingsSection); + var unused1 = services.Configure(appSettingsSection); var appSettings = appSettingsSection.Get(); - byte[] key = Encoding.ASCII.GetBytes(appSettings.Secret); + var key = Encoding.ASCII.GetBytes(appSettings.Secret); - Microsoft.AspNetCore.Authentication.AuthenticationBuilder unused = services.AddAuthentication(options => + var unused = services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; @@ -55,8 +55,8 @@ public static IServiceCollection AddIdentityConfiguration(this IServiceCollectio public static IApplicationBuilder UseIdentityConfiguration(this IApplicationBuilder app) { - app.UseAuthentication(); - app.UseAuthorization(); + _ = app.UseAuthentication(); + _ = app.UseAuthorization(); return app; } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/SwaggerConfig.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/SwaggerConfig.cs index b596d9f..95b6564 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/SwaggerConfig.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Configuration/SwaggerConfig.cs @@ -4,27 +4,27 @@ namespace Browl.Service.AuthSecurity.API.Configuration; public static class SwaggerConfig { - public static IServiceCollection AddSwaggerConfiguration(this IServiceCollection services) - { - IServiceCollection unused = services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo() - { - Title = "Browl Service AuthSecurity API", - Description = "This API guarantees the security and proper authentication of users in the application.", - Contact = new OpenApiContact() { Name = "Rondinele Guimarães", Email = "dev@cia3r.com.br" }, - License = new OpenApiLicense() { Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT") } - }); + public static IServiceCollection AddSwaggerConfiguration(this IServiceCollection services) + { + var unused = services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo() + { + Title = "Browl Service AuthSecurity API", + Description = "This API guarantees the security and proper authentication of users in the application.", + Contact = new OpenApiContact() { Name = "Rondinele Guimarães", Email = "dev@cia3r.com.br" }, + License = new OpenApiLicense() { Name = "MIT", Url = new Uri("https://opensource.org/licenses/MIT") } + }); - }); + }); - return services; - } + return services; + } public static IApplicationBuilder UseSwaggerConfiguration(this IApplicationBuilder app) { - app.UseSwagger(); - app.UseSwaggerUI(c => + var unused1 = app.UseSwagger(); + var unused = app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); }); diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/AuthController.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/AuthController.cs index c573422..351ba8a 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/AuthController.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/AuthController.cs @@ -1,16 +1,15 @@ -using Browl.Service.AuthSecurity.API.Controllers.Base; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; + +using Browl.Service.AuthSecurity.API.Controllers.Base; using Browl.Service.AuthSecurity.API.Entities; -using Browl.Service.AuthSecurity.Domain.Entities; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Tokens; -using System.IdentityModel.Tokens.Jwt; -using System.Security.Claims; -using System.Text; - namespace Browl.Service.AuthSecurity.API.Controllers; /// @@ -81,7 +80,7 @@ public async Task Register(UserRegister userRegister) return CustomResponse(await GenerateJWT(userRegister.Email)); } - foreach (IdentityError error in result.Errors) + foreach (var error in result.Errors) { AddErrorProcessing(error.Description); } @@ -109,7 +108,7 @@ public async Task Login(UserLogin usuarioLogin) return CustomResponse(ModelState); } - Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(usuarioLogin.Email, usuarioLogin.Password, + var result = await _signInManager.PasswordSignInAsync(usuarioLogin.Email, usuarioLogin.Password, false, true); if (result.Succeeded) @@ -150,13 +149,13 @@ private async Task GenerateJWT(string email) /// The claims identity for the user. private async Task GetClaimsUser(ICollection claims, IdentityUser user) { - IList userRoles = await _userManager.GetRolesAsync(user); + var userRoles = await _userManager.GetRolesAsync(user); claims.Add(new Claim(JwtRegisteredClaimNames.Sub, user.Id)); claims.Add(new Claim(JwtRegisteredClaimNames.Email, user.Email)); claims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, ToUnixEpochDate(DateTime.UtcNow).ToString())); claims.Add(new Claim(JwtRegisteredClaimNames.Iat, ToUnixEpochDate(DateTime.UtcNow).ToString(), ClaimValueTypes.Integer64)); - foreach (string userRole in userRoles) + foreach (var userRole in userRoles) { claims.Add(new Claim("role", userRole)); } @@ -185,8 +184,8 @@ private async Task GetClaimsUser(ICollection claims, Iden private string EncodeToken(ClaimsIdentity identityClaims) { JwtSecurityTokenHandler tokenHandler = new(); - byte[] key = Encoding.ASCII.GetBytes(_appSettings.Secret); - SecurityToken token = tokenHandler.CreateToken(new SecurityTokenDescriptor + var key = Encoding.ASCII.GetBytes(_appSettings.Secret); + var token = tokenHandler.CreateToken(new SecurityTokenDescriptor { Issuer = _appSettings.Issuer, Audience = _appSettings.ValidOn, @@ -255,8 +254,5 @@ private UserResponse GetResponseToken(string encodedToken, IdentityUser user, IE /// /// The returned long can be used as a Unix timestamp. /// - private static long ToUnixEpochDate(DateTime date) - { - return DateTimeOffset.UtcNow.ToUnixTimeSeconds(); - } + private static long ToUnixEpochDate(DateTime date) => DateTimeOffset.UtcNow.ToUnixTimeSeconds(); } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/Base/MainController.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/Base/MainController.cs index 51a9ca1..5a43f42 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/Base/MainController.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Controllers/Base/MainController.cs @@ -1,72 +1,65 @@ using Microsoft.AspNetCore.Mvc; -namespace Browl.Service.AuthSecurity.API.Controllers.Base +namespace Browl.Service.AuthSecurity.API.Controllers.Base; + +/// +/// Abstract base controller class that provides common functionality for API controllers. +/// +/// +/// This abstract class defines: +/// - Errors: An IList property to hold a list of error strings. +/// - CustomResponse(): A protected method that returns an ActionResult with custom error handling. +/// - AddErrorProcessing(): A protected method to add an error string to the Errors collection. +/// - ClearErrorsProcessing(): A protected method to clear the Errors collection. +/// +/// Controllers that inherit from this base class can utilize these common members and methods for consistent error handling and responses. +/// +[ApiController] +public abstract class MainController : Controller { + // Collection to store error messages + protected IList Errors = new List(); + /// - /// Abstract base controller class that provides common functionality for API controllers. + /// Custom response method to handle API responses /// - /// - /// This abstract class defines: - /// - Errors: An IList property to hold a list of error strings. - /// - CustomResponse(): A protected method that returns an ActionResult with custom error handling. - /// - AddErrorProcessing(): A protected method to add an error string to the Errors collection. - /// - ClearErrorsProcessing(): A protected method to clear the Errors collection. - /// - /// Controllers that inherit from this base class can utilize these common members and methods for consistent error handling and responses. - /// - [ApiController] - public abstract class MainController : Controller + /// Optional result object + /// Action result + protected ActionResult CustomResponse(object? result = null) { - // Collection to store error messages - protected IList Errors = new List(); - - /// - /// Custom response method to handle API responses - /// - /// Optional result object - /// Action result - protected ActionResult CustomResponse(object? result = null) + // Check if the model state is valid and there are no errors + if (ModelState.IsValid && Errors.Count == 0) { - // Check if the model state is valid and there are no errors - if (ModelState.IsValid && Errors.Count == 0) - { - return Ok(result); - } - - var errorDictionary = new Dictionary(); - - // Add model state errors to the dictionary - if (ModelState.ErrorCount > 0) - { - var modelErrors = ModelState.Values.SelectMany(v => v.Errors); - errorDictionary.Add("Messages", modelErrors.Select(e => e.ErrorMessage).ToArray()); - } - - // Add custom errors to the dictionary - if (Errors.Count > 0) - { - errorDictionary.Add("Messages", Errors.ToArray()); - } - - // Return a bad request response with the validation problem details - return BadRequest(new ValidationProblemDetails(errorDictionary)); + return Ok(result); } - /// - /// Add an error message to the collection - /// - /// Error message - protected void AddErrorProcessing(string error) + var errorDictionary = new Dictionary(); + + // Add model state errors to the dictionary + if (ModelState.ErrorCount > 0) { - Errors.Add(error); + var modelErrors = ModelState.Values.SelectMany(v => v.Errors); + errorDictionary.Add("Messages", modelErrors.Select(e => e.ErrorMessage).ToArray()); } - /// - /// Clear all error messages from the collection - /// - protected void ClearErrorsProcessing() + // Add custom errors to the dictionary + if (Errors.Count > 0) { - Errors.Clear(); + errorDictionary.Add("Messages", Errors.ToArray()); } + + // Return a bad request response with the validation problem details + return BadRequest(new ValidationProblemDetails(errorDictionary)); } + + /// + /// Add an error message to the collection + /// + /// Error message + protected void AddErrorProcessing(string error) => Errors.Add(error); + + /// + /// Clear all error messages from the collection + /// + protected void ClearErrorsProcessing() => Errors.Clear(); } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/BrowlAuthSecurityDbContext.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/BrowlAuthSecurityDbContext.cs index 38f1c7f..1f2b4db 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/BrowlAuthSecurityDbContext.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/BrowlAuthSecurityDbContext.cs @@ -1,4 +1,4 @@ -using Browl.Service.AuthSecurity.Domain.Entities; +using Browl.Service.AuthSecurity.API.Entities; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; @@ -15,40 +15,40 @@ public BrowlAuthSecurityDbContext(DbContextOptions o protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); - builder.HasDefaultSchema("Identity"); - builder.Entity(entity => + var unused14 = builder.HasDefaultSchema("Identity"); + var unused13 = builder.Entity(entity => { - entity.ToTable(name: "User"); + var unused12 = entity.ToTable(name: "User"); }); - builder.Entity(entity => + var unused11 = builder.Entity(entity => { - entity.ToTable(name: "Role"); + var unused10 = entity.ToTable(name: "Role"); }); - builder.Entity>(entity => + var unused9 = builder.Entity>(entity => { - entity.ToTable("UserRoles"); + var unused8 = entity.ToTable("UserRoles"); }); - builder.Entity>(entity => + var unused7 = builder.Entity>(entity => { - entity.ToTable("UserClaims"); + var unused6 = entity.ToTable("UserClaims"); }); - builder.Entity>(entity => + var unused5 = builder.Entity>(entity => { - entity.ToTable("UserLogins"); + var unused4 = entity.ToTable("UserLogins"); }); - builder.Entity>(entity => + var unused3 = builder.Entity>(entity => { - entity.ToTable("RoleClaims"); + var unused2 = entity.ToTable("RoleClaims"); }); - builder.Entity>(entity => + var unused1 = builder.Entity>(entity => { - entity.ToTable("UserTokens"); + var unused = entity.ToTable("UserTokens"); }); } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/ContextSeed.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/ContextSeed.cs index 453200c..f0b9aa7 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/ContextSeed.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Data/ContextSeed.cs @@ -1,45 +1,44 @@ -using Browl.Service.AuthSecurity.Domain.Entities; +using Browl.Service.AuthSecurity.API.Entities; using Microsoft.AspNetCore.Identity; -namespace Browl.Service.AuthSecurity.API.Data +namespace Browl.Service.AuthSecurity.API.Data; + +public static class ContextSeed { - public static class ContextSeed + public static async Task SeedRolesAsync(UserManager userManager, RoleManager roleManager) + { + //Seed Roles + _ = await roleManager.CreateAsync(new IdentityRole(Enums.Roles.SuperAdmin.ToString())); + _ = await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Admin.ToString())); + _ = await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Moderator.ToString())); + _ = await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Basic.ToString())); + } + public static async Task SeedSuperAdminAsync(UserManager userManager, RoleManager roleManager) { - public static async Task SeedRolesAsync(UserManager userManager, RoleManager roleManager) + //Seed Default User + var defaultUser = new User { - //Seed Roles - await roleManager.CreateAsync(new IdentityRole(Enums.Roles.SuperAdmin.ToString())); - await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Admin.ToString())); - await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Moderator.ToString())); - await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Basic.ToString())); - } - public static async Task SeedSuperAdminAsync(UserManager userManager, RoleManager roleManager) + UserName = "rondineleg", + Email = "superadmin@gmail.com", + FirstName = "Rondinele", + LastName = "Guimaraes", + UserNameChangeLimit = 10, + EmailConfirmed = true, + PhoneNumberConfirmed = true + }; + if (userManager.Users.All(u => u.Id != defaultUser.Id)) { - //Seed Default User - var defaultUser = new User + var user = await userManager.FindByEmailAsync(defaultUser.Email); + if (user == null) { - UserName = "rondineleg", - Email = "superadmin@gmail.com", - FirstName = "Rondinele", - LastName = "Guimaraes", - UserNameChangeLimit = 10, - EmailConfirmed = true, - PhoneNumberConfirmed = true - }; - if (userManager.Users.All(u => u.Id != defaultUser.Id)) - { - var user = await userManager.FindByEmailAsync(defaultUser.Email); - if (user == null) - { - await userManager.CreateAsync(defaultUser, "123Pa$$word."); - await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Basic.ToString()); - await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Moderator.ToString()); - await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Admin.ToString()); - await userManager.AddToRoleAsync(defaultUser, Enums.Roles.SuperAdmin.ToString()); - } - + var unused4 = await userManager.CreateAsync(defaultUser, "123Pa$$word."); + var unused3 = await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Basic.ToString()); + var unused2 = await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Moderator.ToString()); + var unused1 = await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Admin.ToString()); + var unused = await userManager.AddToRoleAsync(defaultUser, Enums.Roles.SuperAdmin.ToString()); } + } } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/AppSettings.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/AppSettings.cs index eceef16..021bd08 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/AppSettings.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/AppSettings.cs @@ -1,10 +1,9 @@ -namespace Browl.Service.AuthSecurity.API.Entities +namespace Browl.Service.AuthSecurity.API.Entities; + +public class AppSettings { - public class AppSettings - { - public string Secret { get; set; } - public int ExpirationHours { get; set; } - public string Issuer { get; set; } - public string ValidOn { get; set; } - } + public required string Secret { get; set; } + public int ExpirationHours { get; set; } + public required string Issuer { get; set; } + public required string ValidOn { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/ManageUserRoles.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/ManageUserRoles.cs index 2c18458..d8e2a1f 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/ManageUserRoles.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/ManageUserRoles.cs @@ -1,14 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +namespace Browl.Service.AuthSecurity.API.Entities; -namespace Browl.Service.AuthSecurity.API.Entities +public class ManageUserRoles { - public class ManageUserRoles - { - public string RoleId { get; set; } - public string RoleName { get; set; } - public bool Selected { get; set; } - } + public required string RoleId { get; set; } + public required string RoleName { get; set; } + public bool Selected { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/User.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/User.cs index b8ae1c5..e5249b4 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/User.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/User.cs @@ -1,14 +1,14 @@ using Microsoft.AspNetCore.Identity; -namespace Browl.Service.AuthSecurity.Domain.Entities; +namespace Browl.Service.AuthSecurity.API.Entities; public class User : IdentityUser { - public string UserName { get; set; } - public string FirstName { get; set; } - public string LastName { get; set; } - public int UserNameChangeLimit { get; set; } = 5; - public byte[] ProfilePicture { get; set; } - public string Email { get; set; } - public string Password { get; set; } - public string PasswordConfirmation { get; set; } + public required string UserName { get; set; } + public required string FirstName { get; set; } + public required string LastName { get; set; } + public int UserNameChangeLimit { get; set; } = 5; + public required byte[] ProfilePicture { get; set; } + public required string Email { get; set; } + public required string Password { get; set; } + public required string PasswordConfirmation { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserClaim.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserClaim.cs index 32be97e..a21a716 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserClaim.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserClaim.cs @@ -1,7 +1,7 @@ -namespace Browl.Service.AuthSecurity.Domain.Entities; +namespace Browl.Service.AuthSecurity.API.Entities; public class UserClaim { - public string Value { get; set; } - public string Type { get; set; } + public required string Value { get; set; } + public required string Type { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserLogin.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserLogin.cs index 0a526c1..f8e1070 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserLogin.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserLogin.cs @@ -1,14 +1,14 @@ using System.ComponentModel.DataAnnotations; -namespace Browl.Service.AuthSecurity.Domain.Entities; +namespace Browl.Service.AuthSecurity.API.Entities; public class UserLogin { [Required(ErrorMessage = "Field {0} is mandatory")] [EmailAddress(ErrorMessage = "Field {0} is in an invalid format")] - public string Email { get; set; } + public required string Email { get; set; } [Required(ErrorMessage = "Field {0} is mandatory")] [StringLength(100, ErrorMessage = "Field {0} must be between {2} and {1} characters", MinimumLength = 6)] - public string Password { get; set; } + public required string Password { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRegister.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRegister.cs index d9cf334..dd004c1 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRegister.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRegister.cs @@ -1,30 +1,28 @@ using System.ComponentModel.DataAnnotations; -namespace Browl.Service.AuthSecurity.API.Entities -{ - public class UserRegister - { - [Required(ErrorMessage = "Field {0} is mandatory")] - public string UserName { get; set; } +namespace Browl.Service.AuthSecurity.API.Entities; - [Required(ErrorMessage = "Field {0} is mandatory")] - public string FirstName { get; set; } - [Required(ErrorMessage = "Field {0} is mandatory")] - public string LastName { get; set; } - public int UserNameChangeLimit { get; set; } = 5; - [Required(ErrorMessage = "Field {0} is mandatory")] - public byte[] ProfilePicture { get; set; } +public class UserRegister +{ + [Required(ErrorMessage = "Field {0} is mandatory")] + public required string UserName { get; set; } - [Required(ErrorMessage = "Field {0} is mandatory")] - [EmailAddress(ErrorMessage = "Field {0} is in an invalid format")] - public string Email { get; set; } + [Required(ErrorMessage = "Field {0} is mandatory")] + public required string FirstName { get; set; } + [Required(ErrorMessage = "Field {0} is mandatory")] + public required string LastName { get; set; } + public int UserNameChangeLimit { get; set; } = 5; + [Required(ErrorMessage = "Field {0} is mandatory")] + public required byte[] ProfilePicture { get; set; } - [Required(ErrorMessage = "Field {0} is mandatory")] - [StringLength(100, ErrorMessage = "Field {0} must be between {2} and {1} characters", MinimumLength = 6)] - public string Password { get; set; } + [Required(ErrorMessage = "Field {0} is mandatory")] + [EmailAddress(ErrorMessage = "Field {0} is in an invalid format")] + public required string Email { get; set; } - [Compare("Password", ErrorMessage = "Passwords don't match.")] - public string PasswordConfirmation { get; set; } - } + [Required(ErrorMessage = "Field {0} is mandatory")] + [StringLength(100, ErrorMessage = "Field {0} must be between {2} and {1} characters", MinimumLength = 6)] + public required string Password { get; set; } + [Compare("Password", ErrorMessage = "Passwords don't match.")] + public required string PasswordConfirmation { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserResponse.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserResponse.cs index 4135919..eb712f0 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserResponse.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserResponse.cs @@ -1,7 +1,7 @@ -namespace Browl.Service.AuthSecurity.Domain.Entities; +namespace Browl.Service.AuthSecurity.API.Entities; public class UserResponse { - public string AccessToken { get; set; } + public required string AccessToken { get; set; } public double ExpiresIn { get; set; } - public UserToken UserToken { get; set; } + public required UserToken UserToken { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRoles.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRoles.cs index 5cb94e4..7de4f76 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRoles.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserRoles.cs @@ -1,19 +1,11 @@ -using Microsoft.AspNetCore.Identity; +namespace Browl.Service.AuthSecurity.API.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Browl.Service.AuthSecurity.API.Entities +public class UserRoles { - public class UserRoles - { - public string UserId { get; set; } - public string FirstName { get; set; } - public string LastName { get; set; } - public string UserName { get; set; } - public string Email { get; set; } - public IEnumerable Roles { get; set; } - } + public required string UserId { get; set; } + public required string FirstName { get; set; } + public required string LastName { get; set; } + public required string UserName { get; set; } + public required string Email { get; set; } + public required IEnumerable Roles { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserToken.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserToken.cs index a884a7a..7384d3f 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserToken.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Entities/UserToken.cs @@ -1,7 +1,7 @@ -namespace Browl.Service.AuthSecurity.Domain.Entities; +namespace Browl.Service.AuthSecurity.API.Entities; public class UserToken { - public string Id { get; set; } - public string Email { get; set; } - public IEnumerable UserClaims { get; set; } + public required string Id { get; set; } + public required string Email { get; set; } + public required IEnumerable UserClaims { get; set; } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Enums/Roles.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Enums/Roles.cs index fa5c73f..80b1c5e 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Enums/Roles.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Enums/Roles.cs @@ -1,10 +1,9 @@ -namespace Browl.Service.AuthSecurity.API.Enums +namespace Browl.Service.AuthSecurity.API.Enums; + +public enum Roles { - public enum Roles - { - SuperAdmin, - Admin, - Moderator, - Basic - } + SuperAdmin, + Admin, + Moderator, + Basic } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Migrations/20230916004956_InicialCreate.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Migrations/20230916004956_InicialCreate.cs index c2f77eb..935a0fa 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Migrations/20230916004956_InicialCreate.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Migrations/20230916004956_InicialCreate.cs @@ -1,260 +1,252 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Migrations; #nullable disable -namespace Browl.Service.AuthSecurity.API.Migrations -{ - /// - public partial class InicialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "Identity"); - - migrationBuilder.CreateTable( - name: "Role", - schema: "Identity", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Role", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "User", - schema: "Identity", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), - FirstName = table.Column(type: "nvarchar(max)", nullable: false), - LastName = table.Column(type: "nvarchar(max)", nullable: false), - UserNameChangeLimit = table.Column(type: "int", nullable: false), - ProfilePicture = table.Column(type: "varbinary(max)", nullable: false), - Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - PasswordConfirmation = table.Column(type: "nvarchar(max)", nullable: false), - NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "bit", nullable: false), - PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), - SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), - TwoFactorEnabled = table.Column(type: "bit", nullable: false), - LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), - LockoutEnabled = table.Column(type: "bit", nullable: false), - AccessFailedCount = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_User", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "RoleClaims", - schema: "Identity", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - RoleId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_RoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_RoleClaims_Role_RoleId", - column: x => x.RoleId, - principalSchema: "Identity", - principalTable: "Role", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserClaims", - schema: "Identity", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserClaims", x => x.Id); - table.ForeignKey( - name: "FK_UserClaims_User_UserId", - column: x => x.UserId, - principalSchema: "Identity", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserLogins", - schema: "Identity", - columns: table => new - { - LoginProvider = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), - ProviderKey = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), - ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), - UserId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_UserLogins_User_UserId", - column: x => x.UserId, - principalSchema: "Identity", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserRoles", - schema: "Identity", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - RoleId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_UserRoles_Role_RoleId", - column: x => x.RoleId, - principalSchema: "Identity", - principalTable: "Role", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRoles_User_UserId", - column: x => x.UserId, - principalSchema: "Identity", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserTokens", - schema: "Identity", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - LoginProvider = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), - Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), - Value = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_UserTokens_User_UserId", - column: x => x.UserId, - principalSchema: "Identity", - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - schema: "Identity", - table: "Role", - column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_RoleClaims_RoleId", - schema: "Identity", - table: "RoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - schema: "Identity", - table: "User", - column: "NormalizedEmail"); +namespace Browl.Service.AuthSecurity.API.Migrations; - migrationBuilder.CreateIndex( - name: "UserNameIndex", - schema: "Identity", - table: "User", - column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_UserClaims_UserId", - schema: "Identity", - table: "UserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserLogins_UserId", - schema: "Identity", - table: "UserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRoles_RoleId", - schema: "Identity", - table: "UserRoles", - column: "RoleId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "RoleClaims", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "UserClaims", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "UserLogins", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "UserRoles", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "UserTokens", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "Role", - schema: "Identity"); - - migrationBuilder.DropTable( - name: "User", - schema: "Identity"); - } - } +/// +public partial class InicialCreate : Migration +{ + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + var unused27 = migrationBuilder.EnsureSchema( + name: "Identity"); + + var unused26 = migrationBuilder.CreateTable( + name: "Role", + schema: "Identity", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + var unused25 = table.PrimaryKey("PK_Role", x => x.Id); + }); + + var unused24 = migrationBuilder.CreateTable( + name: "User", + schema: "Identity", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), + FirstName = table.Column(type: "nvarchar(max)", nullable: false), + LastName = table.Column(type: "nvarchar(max)", nullable: false), + UserNameChangeLimit = table.Column(type: "int", nullable: false), + ProfilePicture = table.Column(type: "varbinary(max)", nullable: false), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + PasswordConfirmation = table.Column(type: "nvarchar(max)", nullable: false), + NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + LockoutEnabled = table.Column(type: "bit", nullable: false), + AccessFailedCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + var unused23 = table.PrimaryKey("PK_User", x => x.Id); + }); + + var unused22 = migrationBuilder.CreateTable( + name: "RoleClaims", + schema: "Identity", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + var unused21 = table.PrimaryKey("PK_RoleClaims", x => x.Id); + var unused20 = table.ForeignKey( + name: "FK_RoleClaims_Role_RoleId", + column: x => x.RoleId, + principalSchema: "Identity", + principalTable: "Role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + var unused19 = migrationBuilder.CreateTable( + name: "UserClaims", + schema: "Identity", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + var unused18 = table.PrimaryKey("PK_UserClaims", x => x.Id); + var unused17 = table.ForeignKey( + name: "FK_UserClaims_User_UserId", + column: x => x.UserId, + principalSchema: "Identity", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + var unused16 = migrationBuilder.CreateTable( + name: "UserLogins", + schema: "Identity", + columns: table => new + { + LoginProvider = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + ProviderKey = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + var unused15 = table.PrimaryKey("PK_UserLogins", x => new { x.LoginProvider, x.ProviderKey }); + var unused14 = table.ForeignKey( + name: "FK_UserLogins_User_UserId", + column: x => x.UserId, + principalSchema: "Identity", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + var unused13 = migrationBuilder.CreateTable( + name: "UserRoles", + schema: "Identity", + columns: table => new + { + UserId = table.Column(type: "nvarchar(450)", nullable: false), + RoleId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + var unused12 = table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId }); + var unused11 = table.ForeignKey( + name: "FK_UserRoles_Role_RoleId", + column: x => x.RoleId, + principalSchema: "Identity", + principalTable: "Role", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + var unused10 = table.ForeignKey( + name: "FK_UserRoles_User_UserId", + column: x => x.UserId, + principalSchema: "Identity", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + var unused9 = migrationBuilder.CreateTable( + name: "UserTokens", + schema: "Identity", + columns: table => new + { + UserId = table.Column(type: "nvarchar(450)", nullable: false), + LoginProvider = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: false), + Value = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + var unused8 = table.PrimaryKey("PK_UserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + var unused7 = table.ForeignKey( + name: "FK_UserTokens_User_UserId", + column: x => x.UserId, + principalSchema: "Identity", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + var unused6 = migrationBuilder.CreateIndex( + name: "RoleNameIndex", + schema: "Identity", + table: "Role", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + var unused5 = migrationBuilder.CreateIndex( + name: "IX_RoleClaims_RoleId", + schema: "Identity", + table: "RoleClaims", + column: "RoleId"); + + var unused4 = migrationBuilder.CreateIndex( + name: "EmailIndex", + schema: "Identity", + table: "User", + column: "NormalizedEmail"); + + var unused3 = migrationBuilder.CreateIndex( + name: "UserNameIndex", + schema: "Identity", + table: "User", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + + var unused2 = migrationBuilder.CreateIndex( + name: "IX_UserClaims_UserId", + schema: "Identity", + table: "UserClaims", + column: "UserId"); + + var unused1 = migrationBuilder.CreateIndex( + name: "IX_UserLogins_UserId", + schema: "Identity", + table: "UserLogins", + column: "UserId"); + + var unused = migrationBuilder.CreateIndex( + name: "IX_UserRoles_RoleId", + schema: "Identity", + table: "UserRoles", + column: "RoleId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + _ = migrationBuilder.DropTable( + name: "RoleClaims", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "UserClaims", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "UserLogins", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "UserRoles", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "UserTokens", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "Role", + schema: "Identity"); + _ = migrationBuilder.DropTable( + name: "User", + schema: "Identity"); + } } diff --git a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Program.cs b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Program.cs index d54717f..a852463 100644 --- a/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Program.cs +++ b/src/Services/Browl.Service.AuthSecurity/Browl.Service.AuthSecurity.API/Program.cs @@ -1,9 +1,8 @@ using Browl.Service.AuthSecurity.API.Configuration; using Browl.Service.AuthSecurity.API.Data; -using Browl.Service.AuthSecurity.Domain.Entities; +using Browl.Service.AuthSecurity.API.Entities; using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.Logging; var builder = WebApplication.CreateBuilder(args); builder.Services.AddIdentityConfiguration(builder.Configuration); @@ -15,15 +14,15 @@ app.UseIdentityConfiguration(); app.UseSwaggerConfiguration(); -IServiceProvider services = app.Services; -ILoggerFactory loggerFactory = services.GetRequiredService(); -ILogger logger = loggerFactory.CreateLogger("app"); +var services = app.Services; +var loggerFactory = services.GetRequiredService(); +var logger = loggerFactory.CreateLogger("app"); try { var ser = builder.Services; - + using (var scope = services.CreateScope()) - { + { var context = services.GetRequiredService(); var userManager = services.GetRequiredService>(); var roleManager = services.GetRequiredService>(); @@ -32,18 +31,18 @@ } if (app.Environment.IsDevelopment()) - { + { logger.LogWarning(app.Environment.EnvironmentName, $"EnvironmentName {app.Environment.EnvironmentName}"); Console.WriteLine("Is dev"); } - app.Run(); + app.Run(); } catch (Exception ex) { - logger.LogWarning(ex, "An error occurred seeding the DB"); + logger.LogWarning(ex, "An error occurred seeding the DB"); } finally { - app.Run(); + app.Run(); }