diff --git a/ShowcaseProject/ShowcaseAPI/Data/ApplicationDbContext.cs b/ShowcaseProject/ShowcaseAPI/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..6c6d15b --- /dev/null +++ b/ShowcaseProject/ShowcaseAPI/Data/ApplicationDbContext.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; + +namespace ShowcaseAPI.Data +{ + public class ApplicationDbContext : IdentityDbContext + { + public ApplicationDbContext(DbContextOptions options) : base(options) { } + + protected override void OnModelCreating(ModelBuilder builder) + { + base.OnModelCreating(builder); + } + } +} diff --git a/ShowcaseProject/ShowcaseAPI/Data/DataContext.cs b/ShowcaseProject/ShowcaseAPI/Data/DataContext.cs deleted file mode 100644 index 951aea7..0000000 --- a/ShowcaseProject/ShowcaseAPI/Data/DataContext.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; - -namespace ShowcaseAPI.Data -{ - public class DataContext : IdentityDbContext - { - public DataContext(DbContextOptions options) : base(options) - { - - } - - } -} diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.Designer.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.Designer.cs deleted file mode 100644 index 67480a0..0000000 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.Designer.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ShowcaseAPI.Data; - -#nullable disable - -namespace ShowcaseAPI.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20250204130454_Init")] - partial class Init - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "8.0.12") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.cs deleted file mode 100644 index 02eddb6..0000000 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ShowcaseAPI.Migrations -{ - /// - public partial class InitialCreate : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.Designer.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.Designer.cs deleted file mode 100644 index 017c169..0000000 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.Designer.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using ShowcaseAPI.Data; - -#nullable disable - -namespace ShowcaseAPI.Migrations -{ - [DbContext(typeof(DataContext))] - [Migration("20250204165622_editLoginUserToAuthLoginUser")] - partial class editLoginUserToAuthLoginUser - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "9.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.cs deleted file mode 100644 index dbbba6a..0000000 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204165622_editLoginUserToAuthLoginUser.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ShowcaseAPI.Migrations -{ - /// - public partial class editLoginUserToAuthLoginUser : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.Designer.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.Designer.cs similarity index 98% rename from ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.Designer.cs rename to ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.Designer.cs index cc8583a..359b47f 100644 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204150219_InitialCreate.Designer.cs +++ b/ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.Designer.cs @@ -11,9 +11,9 @@ namespace ShowcaseAPI.Migrations { - [DbContext(typeof(DataContext))] - [Migration("20250204150219_InitialCreate")] - partial class InitialCreate + [DbContext(typeof(ApplicationDbContext))] + [Migration("20251016122639_InitAfterDelete")] + partial class InitAfterDelete { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.cs b/ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.cs similarity index 99% rename from ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.cs rename to ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.cs index b88c5ea..b2c8854 100644 --- a/ShowcaseProject/ShowcaseAPI/Migrations/20250204130454_Init.cs +++ b/ShowcaseProject/ShowcaseAPI/Migrations/20251016122639_InitAfterDelete.cs @@ -6,7 +6,7 @@ namespace ShowcaseAPI.Migrations { /// - public partial class Init : Migration + public partial class InitAfterDelete : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/ShowcaseProject/ShowcaseAPI/Migrations/DataContextModelSnapshot.cs b/ShowcaseProject/ShowcaseAPI/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 98% rename from ShowcaseProject/ShowcaseAPI/Migrations/DataContextModelSnapshot.cs rename to ShowcaseProject/ShowcaseAPI/Migrations/ApplicationDbContextModelSnapshot.cs index eb5e6c6..aa8217f 100644 --- a/ShowcaseProject/ShowcaseAPI/Migrations/DataContextModelSnapshot.cs +++ b/ShowcaseProject/ShowcaseAPI/Migrations/ApplicationDbContextModelSnapshot.cs @@ -10,8 +10,8 @@ namespace ShowcaseAPI.Migrations { - [DbContext(typeof(DataContext))] - partial class DataContextModelSnapshot : ModelSnapshot + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { diff --git a/ShowcaseProject/ShowcaseAPI/Program.cs b/ShowcaseProject/ShowcaseAPI/Program.cs index bbd10e9..001937e 100644 --- a/ShowcaseProject/ShowcaseAPI/Program.cs +++ b/ShowcaseProject/ShowcaseAPI/Program.cs @@ -6,6 +6,7 @@ using ShowcaseAPI.Data; using ShowcaseAPI.Hubs; using System.Text; +using Microsoft.AspNetCore.OpenApi; var builder = WebApplication.CreateBuilder(args); @@ -35,41 +36,38 @@ Env.Load(); -// Add services to the container. -builder.Services.AddAuthentication(options => -{ - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; -}).AddJwtBearer(options => -{ - options.TokenValidationParameters = new TokenValidationParameters - { - ValidIssuer = Environment.GetEnvironmentVariable("JWT_ISSUER"), - ValidAudience = Environment.GetEnvironmentVariable("JWT_AUDIENCE"), - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("JWT_KEY")!)), - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true, - }; -}); +builder.Services.AddDbContext(options => +options.UseSqlServer(Environment.GetEnvironmentVariable("DATABASE_URL"))); builder.Services.AddSignalR(); builder.Services.AddControllers(); - builder.Services.AddEndpointsApiExplorer(); - builder.Services.AddSwaggerGen(); -builder.Services.AddDbContext(options => -options.UseSqlServer(Environment.GetEnvironmentVariable("DATABASE_URL"))); +builder.Services + .AddIdentityCore(options => + { + options.Password.RequiredLength = 12; + options.Password.RequireDigit = false; + options.Password.RequireLowercase = false; + options.Password.RequireUppercase = false; + options.Password.RequireNonAlphanumeric = false; + options.Password.RequiredUniqueChars = 0; -builder.Services.AddAuthorization(); + options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10); + options.Lockout.MaxFailedAccessAttempts = 5; -builder.Services.AddIdentityApiEndpoints() + + }) .AddRoles() - .AddEntityFrameworkStores(); + .AddEntityFrameworkStores() + .AddApiEndpoints() + .AddDefaultTokenProviders(); + +builder.Services.AddAuthentication() + .AddBearerToken(IdentityConstants.BearerScheme); +builder.Services.AddAuthorization(); var app = builder.Build(); // Configure the HTTP request pipeline. @@ -79,7 +77,6 @@ app.UseSwaggerUI(); } -app.MapIdentityApi(); if (!app.Environment.IsDevelopment()) { @@ -101,14 +98,18 @@ app.UseAuthentication(); app.UseAuthorization(); + +app.MapIdentityApi(); + app.MapControllers(); + using (var scope = app.Services.CreateScope()) { var services = scope.ServiceProvider; try { - var context = services.GetRequiredService(); + var context = services.GetRequiredService(); context.Database.Migrate(); } catch (Exception ex) @@ -130,4 +131,5 @@ } } } + app.Run(); \ No newline at end of file diff --git a/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj b/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj index 035d3a7..2e08f1a 100644 --- a/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj +++ b/ShowcaseProject/ShowcaseAPI/ShowcaseAPI.csproj @@ -14,16 +14,21 @@ + - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + diff --git a/ShowcaseProject/ShowcaseAPI/appsettings.Development.json b/ShowcaseProject/ShowcaseAPI/appsettings.Development.json index 0c208ae..d7ac5eb 100644 --- a/ShowcaseProject/ShowcaseAPI/appsettings.Development.json +++ b/ShowcaseProject/ShowcaseAPI/appsettings.Development.json @@ -4,5 +4,8 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } + }, + "ConnectionStrings": { + "DefaultConnection": "Server=sqlserver;Database=ShowcaseDB;User Id=sa;Password=W1ndeshe1mIsDeBeste!;Integrated Security=False;Encrypt=False;TrustServerCertificate=True;" } } diff --git a/ShowcaseProject/ShowcaseApiTesting/Dockerfile b/ShowcaseProject/ShowcaseApiTesting/Dockerfile index 68eab41..cb508d0 100644 --- a/ShowcaseProject/ShowcaseApiTesting/Dockerfile +++ b/ShowcaseProject/ShowcaseApiTesting/Dockerfile @@ -3,6 +3,7 @@ WORKDIR /src COPY ["ShowcaseApiTesting/ShowcaseApiTesting.csproj", "ShowcaseApiTesting/"] COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"] +RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj" RUN dotnet restore "ShowcaseApiTesting/ShowcaseApiTesting.csproj" COPY . . diff --git a/ShowcaseProject/ShowcaseFrontend/ShowcaseFrontend.csproj b/ShowcaseProject/ShowcaseFrontend/ShowcaseFrontend.csproj index 1db4336..43d17af 100644 --- a/ShowcaseProject/ShowcaseFrontend/ShowcaseFrontend.csproj +++ b/ShowcaseProject/ShowcaseFrontend/ShowcaseFrontend.csproj @@ -10,7 +10,7 @@ - + diff --git a/ShowcaseProject/docker-compose.yml b/ShowcaseProject/docker-compose.yml index c21ef7e..601538f 100644 --- a/ShowcaseProject/docker-compose.yml +++ b/ShowcaseProject/docker-compose.yml @@ -33,6 +33,7 @@ services: build: context: . dockerfile: ShowcaseAPI/Dockerfile + target: "final" container_name: showcaseapi ports: - "5001:80"