diff --git a/Kyoo/Controllers/StartupCode.cs b/Kyoo/Controllers/StartupCode.cs index aebe7376..18a95ca3 100644 --- a/Kyoo/Controllers/StartupCode.cs +++ b/Kyoo/Controllers/StartupCode.cs @@ -25,8 +25,7 @@ namespace Kyoo.Controllers using (IServiceScope serviceScope = _serviceProvider.CreateScope()) { serviceScope.ServiceProvider.GetService().Database.Migrate();; - serviceScope.ServiceProvider.GetService().Database.Migrate(); - + ConfigurationDbContext identityContext = serviceScope.ServiceProvider.GetService(); identityContext.Database.Migrate(); if (!identityContext.Clients.Any()) diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index 8c55136c..a34be433 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -18,28 +18,23 @@ - - - - - - - - - - - - - - + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - + + + @@ -90,10 +85,6 @@ PreserveNewest - - - - diff --git a/Kyoo/Models/DatabaseContext.cs b/Kyoo/Models/DatabaseContext.cs index f5842102..d997f6eb 100644 --- a/Kyoo/Models/DatabaseContext.cs +++ b/Kyoo/Models/DatabaseContext.cs @@ -1,17 +1,20 @@ using System; using System.Linq; +using IdentityServer4.EntityFramework.Options; using Kyoo.Models; +using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Microsoft.Extensions.Options; namespace Kyoo { - public class DatabaseContext : IdentityDbContext + public class DatabaseContext : ApiAuthorizationDbContext { - public DatabaseContext(DbContextOptions options) : base(options) { } + public DatabaseContext(DbContextOptions options, IOptions operationalStoreOptions) + : base(options, operationalStoreOptions) { } public DbSet Accounts { get; set; } @@ -66,13 +69,13 @@ namespace Kyoo modelBuilder.Entity() .Ignore(x => x.Genres); - modelBuilder.Entity().ToTable("User"); - modelBuilder.Entity>().ToTable("UserRole"); - modelBuilder.Entity>().ToTable("UserLogin"); - modelBuilder.Entity>().ToTable("UserClaim"); - modelBuilder.Entity().ToTable("UserRoles"); - modelBuilder.Entity>().ToTable("UserRoleClaim"); - modelBuilder.Entity>().ToTable("UserToken"); + // modelBuilder.Entity().ToTable("User"); + // modelBuilder.Entity>().ToTable("UserRole"); + // modelBuilder.Entity>().ToTable("UserLogin"); + // modelBuilder.Entity>().ToTable("UserClaim"); + // modelBuilder.Entity().ToTable("UserRoles"); + // modelBuilder.Entity>().ToTable("UserRoleClaim"); + // modelBuilder.Entity>().ToTable("UserToken"); } } } diff --git a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.Designer.cs b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.Designer.cs similarity index 99% rename from Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.Designer.cs rename to Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.Designer.cs index 78d6720d..02f539af 100644 --- a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.Designer.cs +++ b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.Designer.cs @@ -6,17 +6,17 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace Kyoo.Models.DatabaseMigrations +namespace Kyoo.Models.DatabaseMigrations.IdentityConfiguration { [DbContext(typeof(ConfigurationDbContext))] - [Migration("20200303213949_IS_Configuration")] - partial class IS_Configuration + [Migration("20200330032447_Initial")] + partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); + .HasAnnotation("ProductVersion", "3.1.3"); modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResource", b => { diff --git a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.cs b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.cs similarity index 99% rename from Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.cs rename to Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.cs index b4981bbc..484b19c9 100644 --- a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200303213949_IS_Configuration.cs +++ b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/20200330032447_Initial.cs @@ -1,9 +1,9 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace Kyoo.Models.DatabaseMigrations +namespace Kyoo.Models.DatabaseMigrations.IdentityConfiguration { - public partial class IS_Configuration : Migration + public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { diff --git a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/ConfigurationDbContextModelSnapshot.cs b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/ConfigurationDbContextModelSnapshot.cs index 22c655fe..ed67ec67 100644 --- a/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/ConfigurationDbContextModelSnapshot.cs +++ b/Kyoo/Models/DatabaseMigrations/IdentityConfiguration/ConfigurationDbContextModelSnapshot.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace Kyoo.Models.DatabaseMigrations +namespace Kyoo.Models.DatabaseMigrations.IdentityConfiguration { [DbContext(typeof(ConfigurationDbContext))] partial class ConfigurationDbContextModelSnapshot : ModelSnapshot @@ -14,7 +14,7 @@ namespace Kyoo.Models.DatabaseMigrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); + .HasAnnotation("ProductVersion", "3.1.3"); modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.ApiResource", b => { diff --git a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.Designer.cs b/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.Designer.cs deleted file mode 100644 index 898e36f0..00000000 --- a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.Designer.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -using System; -using IdentityServer4.EntityFramework.DbContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Kyoo.Models.DatabaseMigrations.IdentityPeristant -{ - [DbContext(typeof(PersistedGrantDbContext))] - [Migration("20200303214150_IS_Configuration")] - partial class IS_Configuration - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); - - modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", b => - { - b.Property("UserCode") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("ClientId") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("CreationTime") - .HasColumnType("TEXT"); - - b.Property("Data") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50000); - - b.Property("DeviceCode") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("Expiration") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("SubjectId") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.HasKey("UserCode"); - - b.HasIndex("DeviceCode") - .IsUnique(); - - b.HasIndex("Expiration"); - - b.ToTable("DeviceCodes"); - }); - - modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", b => - { - b.Property("Key") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("ClientId") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("CreationTime") - .HasColumnType("TEXT"); - - b.Property("Data") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50000); - - b.Property("Expiration") - .HasColumnType("TEXT"); - - b.Property("SubjectId") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("Type") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.HasKey("Key"); - - b.HasIndex("Expiration"); - - b.HasIndex("SubjectId", "ClientId", "Type"); - - b.ToTable("PersistedGrants"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.cs b/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.cs deleted file mode 100644 index 3fe0f912..00000000 --- a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/20200303214150_IS_Configuration.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Kyoo.Models.DatabaseMigrations.IdentityPeristant -{ - public partial class IS_Configuration : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "DeviceCodes", - columns: table => new - { - UserCode = table.Column(maxLength: 200, nullable: false), - DeviceCode = table.Column(maxLength: 200, nullable: false), - SubjectId = table.Column(maxLength: 200, nullable: true), - ClientId = table.Column(maxLength: 200, nullable: false), - CreationTime = table.Column(nullable: false), - Expiration = table.Column(nullable: false), - Data = table.Column(maxLength: 50000, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_DeviceCodes", x => x.UserCode); - }); - - migrationBuilder.CreateTable( - name: "PersistedGrants", - columns: table => new - { - Key = table.Column(maxLength: 200, nullable: false), - Type = table.Column(maxLength: 50, nullable: false), - SubjectId = table.Column(maxLength: 200, nullable: true), - ClientId = table.Column(maxLength: 200, nullable: false), - CreationTime = table.Column(nullable: false), - Expiration = table.Column(nullable: true), - Data = table.Column(maxLength: 50000, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PersistedGrants", x => x.Key); - }); - - migrationBuilder.CreateIndex( - name: "IX_DeviceCodes_DeviceCode", - table: "DeviceCodes", - column: "DeviceCode", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_DeviceCodes_Expiration", - table: "DeviceCodes", - column: "Expiration"); - - migrationBuilder.CreateIndex( - name: "IX_PersistedGrants_Expiration", - table: "PersistedGrants", - column: "Expiration"); - - migrationBuilder.CreateIndex( - name: "IX_PersistedGrants_SubjectId_ClientId_Type", - table: "PersistedGrants", - columns: new[] { "SubjectId", "ClientId", "Type" }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "DeviceCodes"); - - migrationBuilder.DropTable( - name: "PersistedGrants"); - } - } -} diff --git a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/PersistedGrantDbContextModelSnapshot.cs b/Kyoo/Models/DatabaseMigrations/IdentityPeristant/PersistedGrantDbContextModelSnapshot.cs deleted file mode 100644 index 3c80c303..00000000 --- a/Kyoo/Models/DatabaseMigrations/IdentityPeristant/PersistedGrantDbContextModelSnapshot.cs +++ /dev/null @@ -1,103 +0,0 @@ -// -using System; -using IdentityServer4.EntityFramework.DbContexts; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -namespace Kyoo.Models.DatabaseMigrations.IdentityPeristant -{ - [DbContext(typeof(PersistedGrantDbContext))] - partial class PersistedGrantDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); - - modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", b => - { - b.Property("UserCode") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("ClientId") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("CreationTime") - .HasColumnType("TEXT"); - - b.Property("Data") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50000); - - b.Property("DeviceCode") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("Expiration") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("SubjectId") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.HasKey("UserCode"); - - b.HasIndex("DeviceCode") - .IsUnique(); - - b.HasIndex("Expiration"); - - b.ToTable("DeviceCodes"); - }); - - modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", b => - { - b.Property("Key") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("ClientId") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("CreationTime") - .HasColumnType("TEXT"); - - b.Property("Data") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50000); - - b.Property("Expiration") - .HasColumnType("TEXT"); - - b.Property("SubjectId") - .HasColumnType("TEXT") - .HasMaxLength(200); - - b.Property("Type") - .IsRequired() - .HasColumnType("TEXT") - .HasMaxLength(50); - - b.HasKey("Key"); - - b.HasIndex("Expiration"); - - b.HasIndex("SubjectId", "ClientId", "Type"); - - b.ToTable("PersistedGrants"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.Designer.cs b/Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.Designer.cs similarity index 87% rename from Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.Designer.cs rename to Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.Designer.cs index 55d95689..8fc847af 100644 --- a/Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.Designer.cs +++ b/Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.Designer.cs @@ -6,17 +6,99 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace Kyoo.Models.DatabaseMigrations.Internal +namespace Kyoo.Models.DatabaseMigrations { [DbContext(typeof(DatabaseContext))] - [Migration("20200316003155_Initial")] + [Migration("20200330024910_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); + .HasAnnotation("ProductVersion", "3.1.3"); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", b => + { + b.Property("UserCode") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Data") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50000); + + b.Property("DeviceCode") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("Expiration") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SubjectId") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.HasKey("UserCode"); + + b.HasIndex("DeviceCode") + .IsUnique(); + + b.HasIndex("Expiration"); + + b.ToTable("DeviceCodes"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", b => + { + b.Property("Key") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Data") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50000); + + b.Property("Expiration") + .HasColumnType("TEXT"); + + b.Property("SubjectId") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("Type") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.HasKey("Key"); + + b.HasIndex("Expiration"); + + b.HasIndex("SubjectId", "ClientId", "Type"); + + b.ToTable("PersistedGrants"); + }); modelBuilder.Entity("Kyoo.Models.Collection", b => { @@ -462,7 +544,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .IsUnique() .HasName("UserNameIndex"); - b.ToTable("User"); + b.ToTable("AspNetUsers"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => @@ -488,7 +570,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .IsUnique() .HasName("RoleNameIndex"); - b.ToTable("UserRoles"); + b.ToTable("AspNetRoles"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -511,7 +593,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("RoleId"); - b.ToTable("UserRoleClaim"); + b.ToTable("AspNetRoleClaims"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => @@ -534,16 +616,18 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("UserId"); - b.ToTable("UserClaim"); + b.ToTable("AspNetUserClaims"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("ProviderKey") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("ProviderDisplayName") .HasColumnType("TEXT"); @@ -556,7 +640,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("UserId"); - b.ToTable("UserLogin"); + b.ToTable("AspNetUserLogins"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -571,7 +655,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("RoleId"); - b.ToTable("UserRole"); + b.ToTable("AspNetUserRoles"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -580,17 +664,19 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .HasColumnType("TEXT"); b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("Value") .HasColumnType("TEXT"); b.HasKey("UserId", "LoginProvider", "Name"); - b.ToTable("UserToken"); + b.ToTable("AspNetUserTokens"); }); modelBuilder.Entity("Kyoo.Models.CollectionLink", b => diff --git a/Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.cs b/Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.cs similarity index 81% rename from Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.cs rename to Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.cs index 40b2e894..0e6b9efe 100644 --- a/Kyoo/Models/DatabaseMigrations/Internal/20200316003155_Initial.cs +++ b/Kyoo/Models/DatabaseMigrations/Internal/20200330024910_Initial.cs @@ -1,12 +1,53 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace Kyoo.Models.DatabaseMigrations.Internal +namespace Kyoo.Models.DatabaseMigrations { public partial class Initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(maxLength: 256, nullable: true), + NormalizedName = table.Column(maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(nullable: false), + UserName = table.Column(maxLength: 256, nullable: true), + NormalizedUserName = table.Column(maxLength: 256, nullable: true), + Email = table.Column(maxLength: 256, nullable: true), + NormalizedEmail = table.Column(maxLength: 256, nullable: true), + EmailConfirmed = table.Column(nullable: false), + PasswordHash = table.Column(nullable: true), + SecurityStamp = table.Column(nullable: true), + ConcurrencyStamp = table.Column(nullable: true), + PhoneNumber = table.Column(nullable: true), + PhoneNumberConfirmed = table.Column(nullable: false), + TwoFactorEnabled = table.Column(nullable: false), + LockoutEnd = table.Column(nullable: true), + LockoutEnabled = table.Column(nullable: false), + AccessFailedCount = table.Column(nullable: false), + OTAC = table.Column(nullable: true), + OTACExpires = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Collections", columns: table => new @@ -24,6 +65,23 @@ namespace Kyoo.Models.DatabaseMigrations.Internal table.PrimaryKey("PK_Collections", x => x.ID); }); + migrationBuilder.CreateTable( + name: "DeviceCodes", + columns: table => new + { + UserCode = table.Column(maxLength: 200, nullable: false), + DeviceCode = table.Column(maxLength: 200, nullable: false), + SubjectId = table.Column(maxLength: 200, nullable: true), + ClientId = table.Column(maxLength: 200, nullable: false), + CreationTime = table.Column(nullable: false), + Expiration = table.Column(nullable: false), + Data = table.Column(maxLength: 50000, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DeviceCodes", x => x.UserCode); + }); + migrationBuilder.CreateTable( name: "Genres", columns: table => new @@ -68,6 +126,23 @@ namespace Kyoo.Models.DatabaseMigrations.Internal table.PrimaryKey("PK_Peoples", x => x.Slug); }); + migrationBuilder.CreateTable( + name: "PersistedGrants", + columns: table => new + { + Key = table.Column(maxLength: 200, nullable: false), + Type = table.Column(maxLength: 50, nullable: false), + SubjectId = table.Column(maxLength: 200, nullable: true), + ClientId = table.Column(maxLength: 200, nullable: false), + CreationTime = table.Column(nullable: false), + Expiration = table.Column(nullable: true), + Data = table.Column(maxLength: 50000, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PersistedGrants", x => x.Key); + }); + migrationBuilder.CreateTable( name: "Studios", columns: table => new @@ -83,44 +158,109 @@ namespace Kyoo.Models.DatabaseMigrations.Internal }); migrationBuilder.CreateTable( - name: "User", + name: "AspNetRoleClaims", columns: table => new { - Id = table.Column(nullable: false), - UserName = table.Column(maxLength: 256, nullable: true), - NormalizedUserName = table.Column(maxLength: 256, nullable: true), - Email = table.Column(maxLength: 256, nullable: true), - NormalizedEmail = table.Column(maxLength: 256, nullable: true), - EmailConfirmed = table.Column(nullable: false), - PasswordHash = table.Column(nullable: true), - SecurityStamp = table.Column(nullable: true), - ConcurrencyStamp = table.Column(nullable: true), - PhoneNumber = table.Column(nullable: true), - PhoneNumberConfirmed = table.Column(nullable: false), - TwoFactorEnabled = table.Column(nullable: false), - LockoutEnd = table.Column(nullable: true), - LockoutEnabled = table.Column(nullable: false), - AccessFailedCount = table.Column(nullable: false), - OTAC = table.Column(nullable: true), - OTACExpires = table.Column(nullable: true) + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + RoleId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) }, constraints: table => { - table.PrimaryKey("PK_User", x => x.Id); + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( - name: "UserRoles", + name: "AspNetUserClaims", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(maxLength: 256, nullable: true), - NormalizedName = table.Column(maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(nullable: true) + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + UserId = table.Column(nullable: false), + ClaimType = table.Column(nullable: true), + ClaimValue = table.Column(nullable: true) }, constraints: table => { - table.PrimaryKey("PK_UserRoles", x => x.Id); + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(maxLength: 128, nullable: false), + ProviderKey = table.Column(maxLength: 128, nullable: false), + ProviderDisplayName = table.Column(nullable: true), + UserId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(nullable: false), + RoleId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(nullable: false), + LoginProvider = table.Column(maxLength: 128, nullable: false), + Name = table.Column(maxLength: 128, nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -157,112 +297,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal onDelete: ReferentialAction.Restrict); }); - migrationBuilder.CreateTable( - name: "UserClaim", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - UserId = table.Column(nullable: false), - ClaimType = table.Column(nullable: true), - ClaimValue = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserClaim", x => x.Id); - table.ForeignKey( - name: "FK_UserClaim_User_UserId", - column: x => x.UserId, - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserLogin", - columns: table => new - { - LoginProvider = table.Column(nullable: false), - ProviderKey = table.Column(nullable: false), - ProviderDisplayName = table.Column(nullable: true), - UserId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserLogin", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_UserLogin_User_UserId", - column: x => x.UserId, - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserToken", - columns: table => new - { - UserId = table.Column(nullable: false), - LoginProvider = table.Column(nullable: false), - Name = table.Column(nullable: false), - Value = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserToken", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_UserToken_User_UserId", - column: x => x.UserId, - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserRole", - columns: table => new - { - UserId = table.Column(nullable: false), - RoleId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRole", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_UserRole_UserRoles_RoleId", - column: x => x.RoleId, - principalTable: "UserRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserRole_User_UserId", - column: x => x.UserId, - principalTable: "User", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "UserRoleClaim", - columns: table => new - { - Id = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - RoleId = table.Column(nullable: false), - ClaimType = table.Column(nullable: true), - ClaimValue = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_UserRoleClaim", x => x.Id); - table.ForeignKey( - name: "FK_UserRoleClaim_UserRoles_RoleId", - column: x => x.RoleId, - principalTable: "UserRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - migrationBuilder.CreateTable( name: "CollectionLinks", columns: table => new @@ -462,6 +496,43 @@ namespace Kyoo.Models.DatabaseMigrations.Internal onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + migrationBuilder.CreateIndex( name: "IX_CollectionLinks_CollectionID", table: "CollectionLinks", @@ -472,6 +543,17 @@ namespace Kyoo.Models.DatabaseMigrations.Internal table: "CollectionLinks", column: "ShowID"); + migrationBuilder.CreateIndex( + name: "IX_DeviceCodes_DeviceCode", + table: "DeviceCodes", + column: "DeviceCode", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_DeviceCodes_Expiration", + table: "DeviceCodes", + column: "Expiration"); + migrationBuilder.CreateIndex( name: "IX_Episodes_SeasonID", table: "Episodes", @@ -512,6 +594,16 @@ namespace Kyoo.Models.DatabaseMigrations.Internal table: "PeopleLinks", column: "ShowID"); + migrationBuilder.CreateIndex( + name: "IX_PersistedGrants_Expiration", + table: "PersistedGrants", + column: "Expiration"); + + migrationBuilder.CreateIndex( + name: "IX_PersistedGrants_SubjectId_ClientId_Type", + table: "PersistedGrants", + columns: new[] { "SubjectId", "ClientId", "Type" }); + migrationBuilder.CreateIndex( name: "IX_Seasons_ShowID", table: "Seasons", @@ -526,50 +618,31 @@ namespace Kyoo.Models.DatabaseMigrations.Internal name: "IX_Tracks_EpisodeID", table: "Tracks", column: "EpisodeID"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "User", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "User", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_UserClaim_UserId", - table: "UserClaim", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserLogin_UserId", - table: "UserLogin", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRole_RoleId", - table: "UserRole", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "IX_UserRoleClaim_RoleId", - table: "UserRoleClaim", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "UserRoles", - column: "NormalizedName", - unique: true); } protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + migrationBuilder.DropTable( name: "CollectionLinks"); + migrationBuilder.DropTable( + name: "DeviceCodes"); + migrationBuilder.DropTable( name: "GenreLinks"); @@ -579,23 +652,17 @@ namespace Kyoo.Models.DatabaseMigrations.Internal migrationBuilder.DropTable( name: "PeopleLinks"); + migrationBuilder.DropTable( + name: "PersistedGrants"); + migrationBuilder.DropTable( name: "Tracks"); migrationBuilder.DropTable( - name: "UserClaim"); + name: "AspNetRoles"); migrationBuilder.DropTable( - name: "UserLogin"); - - migrationBuilder.DropTable( - name: "UserRole"); - - migrationBuilder.DropTable( - name: "UserRoleClaim"); - - migrationBuilder.DropTable( - name: "UserToken"); + name: "AspNetUsers"); migrationBuilder.DropTable( name: "Genres"); @@ -612,12 +679,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal migrationBuilder.DropTable( name: "Episodes"); - migrationBuilder.DropTable( - name: "UserRoles"); - - migrationBuilder.DropTable( - name: "User"); - migrationBuilder.DropTable( name: "Seasons"); diff --git a/Kyoo/Models/DatabaseMigrations/Internal/DatabaseContextModelSnapshot.cs b/Kyoo/Models/DatabaseMigrations/Internal/DatabaseContextModelSnapshot.cs index 10d770c7..1fd162e4 100644 --- a/Kyoo/Models/DatabaseMigrations/Internal/DatabaseContextModelSnapshot.cs +++ b/Kyoo/Models/DatabaseMigrations/Internal/DatabaseContextModelSnapshot.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -namespace Kyoo.Models.DatabaseMigrations.Internal +namespace Kyoo.Models.DatabaseMigrations { [DbContext(typeof(DatabaseContext))] partial class DatabaseContextModelSnapshot : ModelSnapshot @@ -14,7 +14,89 @@ namespace Kyoo.Models.DatabaseMigrations.Internal { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.2"); + .HasAnnotation("ProductVersion", "3.1.3"); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.DeviceFlowCodes", b => + { + b.Property("UserCode") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Data") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50000); + + b.Property("DeviceCode") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("Expiration") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SubjectId") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.HasKey("UserCode"); + + b.HasIndex("DeviceCode") + .IsUnique(); + + b.HasIndex("Expiration"); + + b.ToTable("DeviceCodes"); + }); + + modelBuilder.Entity("IdentityServer4.EntityFramework.Entities.PersistedGrant", b => + { + b.Property("Key") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("ClientId") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("CreationTime") + .HasColumnType("TEXT"); + + b.Property("Data") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50000); + + b.Property("Expiration") + .HasColumnType("TEXT"); + + b.Property("SubjectId") + .HasColumnType("TEXT") + .HasMaxLength(200); + + b.Property("Type") + .IsRequired() + .HasColumnType("TEXT") + .HasMaxLength(50); + + b.HasKey("Key"); + + b.HasIndex("Expiration"); + + b.HasIndex("SubjectId", "ClientId", "Type"); + + b.ToTable("PersistedGrants"); + }); modelBuilder.Entity("Kyoo.Models.Collection", b => { @@ -460,7 +542,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .IsUnique() .HasName("UserNameIndex"); - b.ToTable("User"); + b.ToTable("AspNetUsers"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => @@ -486,7 +568,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .IsUnique() .HasName("RoleNameIndex"); - b.ToTable("UserRoles"); + b.ToTable("AspNetRoles"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -509,7 +591,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("RoleId"); - b.ToTable("UserRoleClaim"); + b.ToTable("AspNetRoleClaims"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => @@ -532,16 +614,18 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("UserId"); - b.ToTable("UserClaim"); + b.ToTable("AspNetUserClaims"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("ProviderKey") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("ProviderDisplayName") .HasColumnType("TEXT"); @@ -554,7 +638,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("UserId"); - b.ToTable("UserLogin"); + b.ToTable("AspNetUserLogins"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -569,7 +653,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal b.HasIndex("RoleId"); - b.ToTable("UserRole"); + b.ToTable("AspNetUserRoles"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -578,17 +662,19 @@ namespace Kyoo.Models.DatabaseMigrations.Internal .HasColumnType("TEXT"); b.Property("LoginProvider") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("Name") - .HasColumnType("TEXT"); + .HasColumnType("TEXT") + .HasMaxLength(128); b.Property("Value") .HasColumnType("TEXT"); b.HasKey("UserId", "LoginProvider", "Name"); - b.ToTable("UserToken"); + b.ToTable("AspNetUserTokens"); }); modelBuilder.Entity("Kyoo.Models.CollectionLink", b => diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs index 6e2f119b..e5ba03ef 100644 --- a/Kyoo/Program.cs +++ b/Kyoo/Program.cs @@ -1,12 +1,7 @@ using System; using System.Threading.Tasks; -using Kyoo.Controllers; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.DependencyInjection; -using Serilog; -using Serilog.Events; -using Serilog.Sinks.SystemConsole.Themes; namespace Kyoo { @@ -14,25 +9,12 @@ namespace Kyoo { public static async Task Main(string[] args) { - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() - .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("System", LogEventLevel.Warning) - .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) - .Enrich.FromLogContext() - .WriteTo.Console( - outputTemplate: - "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", - theme: AnsiConsoleTheme.Literate) - .CreateLogger(); - Console.WriteLine($"Running as: {Environment.UserName}"); await CreateWebHostBuilder(args).Build().RunAsync(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) - .UseSerilog() .UseKestrel((config) => { config.AddServerHeader = false; }) .UseUrls("http://*:5000") .UseStartup(); diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 196cf25d..7acfcf68 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -1,14 +1,10 @@ -using System; -using System.Net; using System.Reflection; -using System.Threading.Tasks; using Kyoo.Api; using Kyoo.Controllers; using Kyoo.Models; -using Microsoft.AspNetCore.Authentication.Cookies; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.SpaServices.AngularCli; using Microsoft.EntityFrameworkCore; @@ -30,29 +26,27 @@ namespace Kyoo // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - services.Configure(options => + // services.AddSpaStaticFiles(configuration => + // { + // configuration.RootPath = "wwwroot"; + // }); + // + // services.AddControllers().AddNewtonsoftJson(); + // services.AddHttpClient(); + // + // string publicUrl = Configuration.GetValue("public_url"); + // + services.AddDbContext(options => { - options.MinimumSameSitePolicy = SameSiteMode.Lax; + options.UseLazyLoadingProxies() + .UseSqlite(Configuration.GetConnectionString("Database")); }); - - // In production, the Angular files will be served from this directory - services.AddSpaStaticFiles(configuration => - { - configuration.RootPath = "wwwroot"; - }); - - services.AddControllers().AddNewtonsoftJson(); - services.AddHttpClient(); string assemblyName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name; string publicUrl = Configuration.GetValue("public_url"); - - services.AddDbContext(options => options.UseLazyLoadingProxies() - .UseSqlite(Configuration.GetConnectionString("Database"))); - services.AddIdentity() - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); + services.AddDefaultIdentity() + .AddEntityFrameworkStores(); services.AddIdentityServer(options => { @@ -60,6 +54,8 @@ namespace Kyoo options.UserInteraction.ErrorUrl = publicUrl + "error"; options.UserInteraction.LogoutUrl = publicUrl + "logout"; }) + .AddAspNetIdentity() + .AddSigningCredentials() .AddConfigurationStore(options => { options.ConfigureDbContext = builder => @@ -75,32 +71,34 @@ namespace Kyoo }) .AddInMemoryIdentityResources(IdentityContext.GetIdentityResources()) .AddInMemoryApiResources(IdentityContext.GetApis()) - .AddAspNetIdentity() .AddProfileService() .AddDeveloperSigningCredential(); // TODO remove the developer signin + + services.AddAuthentication() + .AddIdentityServerJwt(); + + // services.ConfigureApplicationCookie(options => + // { + // options.Events.OnRedirectToAccessDenied = context => + // { + // context.Response.StatusCode = (int)HttpStatusCode.Forbidden; + // return Task.CompletedTask; + // }; + // options.Events.OnRedirectToLogin = context => + // { + // context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; + // return Task.CompletedTask; + // }; + // }); - services.ConfigureApplicationCookie(options => - { - options.Events.OnRedirectToAccessDenied = context => - { - context.Response.StatusCode = (int)HttpStatusCode.Forbidden; - return Task.CompletedTask; - }; - options.Events.OnRedirectToLogin = context => - { - context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; - return Task.CompletedTask; - }; - }); - - services.AddAuthorization(options => - { - options.AddPolicy("Read", policy => policy.RequireClaim("read")); - options.AddPolicy("Write", policy => policy.RequireClaim("write")); - options.AddPolicy("Play", policy => policy.RequireClaim("play")); - options.AddPolicy("Download", policy => policy.RequireClaim("download")); - options.AddPolicy("Admin", policy => policy.RequireClaim("admin")); - }); + // services.AddAuthorization(options => + // { + // options.AddPolicy("Read", policy => policy.RequireClaim("read")); + // options.AddPolicy("Write", policy => policy.RequireClaim("write")); + // options.AddPolicy("Play", policy => policy.RequireClaim("play")); + // options.AddPolicy("Download", policy => policy.RequireClaim("download")); + // options.AddPolicy("Admin", policy => policy.RequireClaim("admin")); + // }); services.AddScoped(); services.AddScoped(); @@ -125,20 +123,18 @@ namespace Kyoo app.UseHsts(); } - app.Use((ctx, next) => - { - ctx.Response.Headers.Remove("X-Powered-By"); - ctx.Response.Headers.Remove("Server"); - ctx.Response.Headers.Add("Feature-Policy", "autoplay 'self'; fullscreen"); - ctx.Response.Headers.Add("Content-Security-Policy", "default-src 'self' data: blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:; style-src 'self' 'unsafe-inline'"); - ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); - ctx.Response.Headers.Add("Referrer-Policy", "no-referrer"); - ctx.Response.Headers.Add("Access-Control-Allow-Origin", "null"); - ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff"); - return next(); - }); - - app.UseCookiePolicy(); + // app.Use((ctx, next) => + // { + // ctx.Response.Headers.Remove("X-Powered-By"); + // ctx.Response.Headers.Remove("Server"); + // ctx.Response.Headers.Add("Feature-Policy", "autoplay 'self'; fullscreen"); + // ctx.Response.Headers.Add("Content-Security-Policy", "default-src 'self' data: blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:; style-src 'self' 'unsafe-inline'"); + // ctx.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); + // ctx.Response.Headers.Add("Referrer-Policy", "no-referrer"); + // ctx.Response.Headers.Add("Access-Control-Allow-Origin", "null"); + // ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff"); + // return next(); + // }); app.UseStaticFiles(); if (!env.IsDevelopment()) @@ -146,12 +142,13 @@ namespace Kyoo app.UseRouting(); + app.UseAuthentication(); app.UseIdentityServer(); app.UseAuthorization(); - + app.UseEndpoints(endpoints => { - endpoints.MapControllerRoute("API Route", "api/{controller=Home}/{action=Index}/{id?}"); + endpoints.MapControllerRoute("Kyoo", "api/{controller=Home}/{action=Index}/{id?}"); }); app.UseSpa(spa => diff --git a/Kyoo/Views/API/AccountAPI.cs b/Kyoo/Views/API/AccountAPI.cs index 015915de..1eea4b5f 100644 --- a/Kyoo/Views/API/AccountAPI.cs +++ b/Kyoo/Views/API/AccountAPI.cs @@ -18,16 +18,16 @@ namespace Kyoo.Api { public class RegisterRequest { - public string Email; - public string Username; - public string Password; + public string Email { get; set; } + public string Username { get; set; } + public string Password { get; set; } } public class LoginRequest { - public string Username; - public string Password; - public bool StayLoggedIn; + public string Username { get; set; } + public string Password { get; set; } + public bool StayLoggedIn { get; set; } } public class OtacRequest diff --git a/Kyoo/Views/API/ShowsAPI.cs b/Kyoo/Views/API/ShowsAPI.cs index 67913293..05beb8bb 100644 --- a/Kyoo/Views/API/ShowsAPI.cs +++ b/Kyoo/Views/API/ShowsAPI.cs @@ -19,7 +19,7 @@ namespace Kyoo.Api } [HttpGet] - [Authorize(Policy="Read")] + [Authorize] public IEnumerable GetShows() { return _libraryManager.GetShows(); diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 04e92944..3f17ec96 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 04e92944eeb2f5617834253d01ef312fee46e435 +Subproject commit 3f17ec96dac6cc641b875a0e3b201b8b75336d6d diff --git a/Kyoo/appsettings.json b/Kyoo/appsettings.json index 19b8e81a..fe56e208 100644 --- a/Kyoo/appsettings.json +++ b/Kyoo/appsettings.json @@ -4,7 +4,9 @@ "https_port": 44300, "Logging": { "LogLevel": { - "Default": "Warning" + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*", @@ -13,6 +15,12 @@ "Database": "Data Source=kyoo.db" }, + "IdentityServer": { + "Key": { + "Type": "Development" + } + }, + "transmuxTempPath": "cached/kyoo/transmux", "transcodeTempPath": "cached/kyoo/transcode", "peoplePath": "people",