Making authorization work better

This commit is contained in:
Zoe Roux 2020-03-30 22:13:50 +02:00
parent 048050f81b
commit e98efae978
10 changed files with 226 additions and 219 deletions

View File

@ -69,13 +69,13 @@ namespace Kyoo
modelBuilder.Entity<Show>() modelBuilder.Entity<Show>()
.Ignore(x => x.Genres); .Ignore(x => x.Genres);
// modelBuilder.Entity<User>().ToTable("User"); modelBuilder.Entity<User>().ToTable("User");
// modelBuilder.Entity<IdentityUserRole<string>>().ToTable("UserRole"); modelBuilder.Entity<IdentityUserRole<string>>().ToTable("UserRole");
// modelBuilder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin"); modelBuilder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
// modelBuilder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim"); modelBuilder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim");
// modelBuilder.Entity<IdentityRole>().ToTable("UserRoles"); modelBuilder.Entity<IdentityRole>().ToTable("UserRoles");
// modelBuilder.Entity<IdentityRoleClaim<string>>().ToTable("UserRoleClaim"); modelBuilder.Entity<IdentityRoleClaim<string>>().ToTable("UserRoleClaim");
// modelBuilder.Entity<IdentityUserToken<string>>().ToTable("UserToken"); modelBuilder.Entity<IdentityUserToken<string>>().ToTable("UserToken");
} }
} }
} }

View File

@ -6,10 +6,10 @@ using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.Models.DatabaseMigrations namespace Kyoo.Models.DatabaseMigrations.Internal
{ {
[DbContext(typeof(DatabaseContext))] [DbContext(typeof(DatabaseContext))]
[Migration("20200330024910_Initial")] [Migration("20200330171153_Initial")]
partial class Initial partial class Initial
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -544,7 +544,7 @@ namespace Kyoo.Models.DatabaseMigrations
.IsUnique() .IsUnique()
.HasName("UserNameIndex"); .HasName("UserNameIndex");
b.ToTable("AspNetUsers"); b.ToTable("User");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
@ -570,7 +570,7 @@ namespace Kyoo.Models.DatabaseMigrations
.IsUnique() .IsUnique()
.HasName("RoleNameIndex"); .HasName("RoleNameIndex");
b.ToTable("AspNetRoles"); b.ToTable("UserRoles");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
@ -593,7 +593,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("RoleId"); b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims"); b.ToTable("UserRoleClaim");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
@ -616,7 +616,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("AspNetUserClaims"); b.ToTable("UserClaim");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
@ -640,7 +640,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("AspNetUserLogins"); b.ToTable("UserLogin");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
@ -655,7 +655,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("RoleId"); b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles"); b.ToTable("UserRole");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
@ -676,7 +676,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasKey("UserId", "LoginProvider", "Name"); b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens"); b.ToTable("UserToken");
}); });
modelBuilder.Entity("Kyoo.Models.CollectionLink", b => modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>

View File

@ -1,53 +1,12 @@
using System; using System;
using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Migrations;
namespace Kyoo.Models.DatabaseMigrations namespace Kyoo.Models.DatabaseMigrations.Internal
{ {
public partial class Initial : Migration public partial class Initial : Migration
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(nullable: false),
Name = table.Column<string>(maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUsers",
columns: table => new
{
Id = table.Column<string>(nullable: false),
UserName = table.Column<string>(maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
Email = table.Column<string>(maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
OTAC = table.Column<string>(nullable: true),
OTACExpires = table.Column<DateTime>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUsers", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Collections", name: "Collections",
columns: table => new columns: table => new
@ -158,109 +117,44 @@ namespace Kyoo.Models.DatabaseMigrations
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "AspNetRoleClaims", name: "User",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<string>(nullable: false),
.Annotation("Sqlite:Autoincrement", true), UserName = table.Column<string>(maxLength: 256, nullable: true),
RoleId = table.Column<string>(nullable: false), NormalizedUserName = table.Column<string>(maxLength: 256, nullable: true),
ClaimType = table.Column<string>(nullable: true), Email = table.Column<string>(maxLength: 256, nullable: true),
ClaimValue = table.Column<string>(nullable: true) NormalizedEmail = table.Column<string>(maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(nullable: false),
PasswordHash = table.Column<string>(nullable: true),
SecurityStamp = table.Column<string>(nullable: true),
ConcurrencyStamp = table.Column<string>(nullable: true),
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
OTAC = table.Column<string>(nullable: true),
OTACExpires = table.Column<DateTime>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); table.PrimaryKey("PK_User", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "AspNetUserClaims", name: "UserRoles",
columns: table => new columns: table => new
{ {
Id = table.Column<int>(nullable: false) Id = table.Column<string>(nullable: false),
.Annotation("Sqlite:Autoincrement", true), Name = table.Column<string>(maxLength: 256, nullable: true),
UserId = table.Column<string>(nullable: false), NormalizedName = table.Column<string>(maxLength: 256, nullable: true),
ClaimType = table.Column<string>(nullable: true), ConcurrencyStamp = table.Column<string>(nullable: true)
ClaimValue = table.Column<string>(nullable: true)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); table.PrimaryKey("PK_UserRoles", 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<string>(maxLength: 128, nullable: false),
ProviderKey = table.Column<string>(maxLength: 128, nullable: false),
ProviderDisplayName = table.Column<string>(nullable: true),
UserId = table.Column<string>(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<string>(nullable: false),
RoleId = table.Column<string>(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<string>(nullable: false),
LoginProvider = table.Column<string>(maxLength: 128, nullable: false),
Name = table.Column<string>(maxLength: 128, nullable: false),
Value = table.Column<string>(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( migrationBuilder.CreateTable(
@ -297,6 +191,112 @@ namespace Kyoo.Models.DatabaseMigrations
onDelete: ReferentialAction.Restrict); onDelete: ReferentialAction.Restrict);
}); });
migrationBuilder.CreateTable(
name: "UserClaim",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserId = table.Column<string>(nullable: false),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(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<string>(maxLength: 128, nullable: false),
ProviderKey = table.Column<string>(maxLength: 128, nullable: false),
ProviderDisplayName = table.Column<string>(nullable: true),
UserId = table.Column<string>(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<string>(nullable: false),
LoginProvider = table.Column<string>(maxLength: 128, nullable: false),
Name = table.Column<string>(maxLength: 128, nullable: false),
Value = table.Column<string>(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<string>(nullable: false),
RoleId = table.Column<string>(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<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
RoleId = table.Column<string>(nullable: false),
ClaimType = table.Column<string>(nullable: true),
ClaimValue = table.Column<string>(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( migrationBuilder.CreateTable(
name: "CollectionLinks", name: "CollectionLinks",
columns: table => new columns: table => new
@ -496,43 +496,6 @@ namespace Kyoo.Models.DatabaseMigrations
onDelete: ReferentialAction.Cascade); 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( migrationBuilder.CreateIndex(
name: "IX_CollectionLinks_CollectionID", name: "IX_CollectionLinks_CollectionID",
table: "CollectionLinks", table: "CollectionLinks",
@ -618,25 +581,47 @@ namespace Kyoo.Models.DatabaseMigrations
name: "IX_Tracks_EpisodeID", name: "IX_Tracks_EpisodeID",
table: "Tracks", table: "Tracks",
column: "EpisodeID"); 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) 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( migrationBuilder.DropTable(
name: "CollectionLinks"); name: "CollectionLinks");
@ -659,10 +644,19 @@ namespace Kyoo.Models.DatabaseMigrations
name: "Tracks"); name: "Tracks");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "AspNetRoles"); name: "UserClaim");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "AspNetUsers"); name: "UserLogin");
migrationBuilder.DropTable(
name: "UserRole");
migrationBuilder.DropTable(
name: "UserRoleClaim");
migrationBuilder.DropTable(
name: "UserToken");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Genres"); name: "Genres");
@ -679,6 +673,12 @@ namespace Kyoo.Models.DatabaseMigrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Episodes"); name: "Episodes");
migrationBuilder.DropTable(
name: "UserRoles");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Seasons"); name: "Seasons");

View File

@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.Models.DatabaseMigrations namespace Kyoo.Models.DatabaseMigrations.Internal
{ {
[DbContext(typeof(DatabaseContext))] [DbContext(typeof(DatabaseContext))]
partial class DatabaseContextModelSnapshot : ModelSnapshot partial class DatabaseContextModelSnapshot : ModelSnapshot
@ -542,7 +542,7 @@ namespace Kyoo.Models.DatabaseMigrations
.IsUnique() .IsUnique()
.HasName("UserNameIndex"); .HasName("UserNameIndex");
b.ToTable("AspNetUsers"); b.ToTable("User");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
@ -568,7 +568,7 @@ namespace Kyoo.Models.DatabaseMigrations
.IsUnique() .IsUnique()
.HasName("RoleNameIndex"); .HasName("RoleNameIndex");
b.ToTable("AspNetRoles"); b.ToTable("UserRoles");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
@ -591,7 +591,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("RoleId"); b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims"); b.ToTable("UserRoleClaim");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
@ -614,7 +614,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("AspNetUserClaims"); b.ToTable("UserClaim");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
@ -638,7 +638,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("UserId"); b.HasIndex("UserId");
b.ToTable("AspNetUserLogins"); b.ToTable("UserLogin");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
@ -653,7 +653,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasIndex("RoleId"); b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles"); b.ToTable("UserRole");
}); });
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b => modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
@ -674,7 +674,7 @@ namespace Kyoo.Models.DatabaseMigrations
b.HasKey("UserId", "LoginProvider", "Name"); b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens"); b.ToTable("UserToken");
}); });
modelBuilder.Entity("Kyoo.Models.CollectionLink", b => modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>

View File

@ -84,11 +84,11 @@ namespace Kyoo
services.AddAuthorization(options => services.AddAuthorization(options =>
{ {
options.AddPolicy("Read", policy => policy.RequireScope("kyoo.read").RequireClaim("read")); options.AddPolicy("Read", policy => policy.RequireScope("kyoo.read").RequireClaim("kyoo.read")); //Checked from the access token so kyoo.read is not here but it is inside the permissions string-array.
options.AddPolicy("Write", policy => policy.RequireScope("kyoo.write").RequireClaim("write")); options.AddPolicy("Write", policy => policy.RequireScope("kyoo.write").RequireClaim("kyoo.write"));
options.AddPolicy("Play", policy => policy.RequireScope("kyoo.play").RequireClaim("play")); options.AddPolicy("Play", policy => policy.RequireScope("kyoo.play").RequireClaim("kyoo.play"));
options.AddPolicy("Download", policy => policy.RequireScope("kyoo.download").RequireClaim("download")); options.AddPolicy("Download", policy => policy.RequireScope("kyoo.download").RequireClaim("kyoo.download"));
options.AddPolicy("Admin", policy => policy.RequireScope("kyoo.admin").RequireClaim("admin")); options.AddPolicy("Admin", policy => policy.RequireScope("kyoo.admin").RequireClaim("kyoo.admin"));
}); });
services.AddScoped<ILibraryManager, LibraryManager>(); services.AddScoped<ILibraryManager, LibraryManager>();

View File

@ -55,8 +55,8 @@ namespace Kyoo.Api
public Claim[] defaultClaims = public Claim[] defaultClaims =
{ {
new Claim("read", ""), new Claim("kyoo.read", ""),
new Claim("play", "") new Claim("kyoo.play", "")
}; // TODO should add this field on the server's configuration page. }; // TODO should add this field on the server's configuration page.
public AccountController(UserManager<User> userManager, SignInManager<User> siginInManager, IConfiguration configuration) public AccountController(UserManager<User> userManager, SignInManager<User> siginInManager, IConfiguration configuration)
@ -125,6 +125,10 @@ namespace Kyoo.Api
new Claim("username", user.UserName), new Claim("username", user.UserName),
new Claim("picture", $"api/account/picture/{user.UserName}") new Claim("picture", $"api/account/picture/{user.UserName}")
}; };
IList<Claim> userClaims = await _userManager.GetClaimsAsync(user);
IEnumerable<string> permissions = from claim in userClaims where claim.Type.StartsWith("kyoo.") select claim.Type.Substring(claim.Type.IndexOf(".") + 1);
claims.Add(new Claim("permissions", string.Join(",", permissions)));
context.IssuedClaims.AddRange(claims); context.IssuedClaims.AddRange(claims);
} }

View File

@ -3,6 +3,7 @@ using Kyoo.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Authorization;
namespace Kyoo.Api namespace Kyoo.Api
{ {
@ -24,6 +25,7 @@ namespace Kyoo.Api
} }
[HttpGet("{librarySlug}")] [HttpGet("{librarySlug}")]
[Authorize(Policy="Read")]
public ActionResult<IEnumerable<Show>> GetShows(string librarySlug) public ActionResult<IEnumerable<Show>> GetShows(string librarySlug)
{ {
Library library = _libraryManager.GetLibrary(librarySlug); Library library = _libraryManager.GetLibrary(librarySlug);

View File

@ -19,7 +19,7 @@ namespace Kyoo.Api
} }
[HttpGet] [HttpGet]
[Authorize] [Authorize(Policy="Read")]
public IEnumerable<Show> GetShows() public IEnumerable<Show> GetShows()
{ {
return _libraryManager.GetShows(); return _libraryManager.GetShows();

@ -1 +1 @@
Subproject commit 92924ddfb62306c3e6ed7fe6462317f920686962 Subproject commit d0a4ef3fdf6b25b64a160d0feae3223afadc8236

1
Kyoo/tempkey.rsa Normal file
View File

@ -0,0 +1 @@
{"KeyId":"mkaygTF8pb-42wV_HvSUCQ","Parameters":{"D":"usyImLSKe8Gvh65XyygNoe9bCffxcB9maRAAL9tXou89QHc4WhPvCjRDlryOwNUxNWJvduDXJm+AenWbSx7/PNVzaKaK6j/GKt9OMsD//9ubEswP9zhNFn9zAzmWsp2wSMEM+1fU6VcXc9MCwjySP3DtHiw3ZwFUvfP4pm3PhKwaI3TKe2rmB9mwziiv9SSd+bwbKlVlGmMM4UVMwD/VYmJZZMB8NaQY2PmdJHztyp4NYJIMFnGFaJVN9GSFC1qv2btKhlZrL7InGdATbzUC82+Ff0st5YX4omJyb8DJ25SiCSXzKkeLWafcCedYdJwIPSxAgd9edCQLUNvORa26qQ==","DP":"0x2WZoveXkd9cYs4xGpL3cKmg5RQe1IBNy19tqLhpiCOqtzgz7agCbEBSsHsPQVclrQMp+GvBbuWTKEAj4DR/N2o+ir6V0W80VN8/2K4PX7wo9ryJAmUXNp4b231ubJv4neDGqF2j0g+WWxt5Gh6gx+FJjkGENYs5VJ7kFSc+fs=","DQ":"HQr0bM//+68PwegI6PSmFYgNMciMsnXGpn9xElU2Ed8EiF8dRW3LBjl8y3tsuZVwHbteZtlZJqUtd0kuwkC+5Kts1dEds8FOXfrZgpt/n+APOr14707yaxrcWhGkJu9kCjRsAbhsxtScxQE/sUb+5naTF5ypmORplL3O6ZnJ8L0=","Exponent":"AQAB","InverseQ":"IYckPpRj0eq7UF3YrzSt7sLPYdz/S1nfBJl4gNKEYvnwysaxg2iOq2u/4hu7+r1Jf8+j6e1dcOJqN4jPXyq2ycQ0X5BLNHENXBjvRrfaUD35bBMz2vKRq423sXPAV2k1Mpt6StZSAjyxF741IIQ+X1W5IVuuO9awK9ruw9bpR2I=","Modulus":"yoIp2j1kI5sku7k16xJNLEt7uw4LQY+UX3onsgdf69aNNXk2j6IyoW6dE9lAGRYKsNkKSH2kvUBTHCX78j0Mg0dInNyB1s7MgS5t8ypc4y5lIE+xFEXKAKeH6lZ9NC+PNwtCSY9iNAteiPO1ittmzkS7QR9fgHQ/8NwYuU3AxQUxf5QULuYWIE4rKryQHqlQzqvg7cZizcuINXxG3oUiSGWg1aYQUcjY07wWJFvVwsV7pjKTSL0edDCoqg8bQ/F97aDuP4e0QKaALs1GkXb854Kp977EitxLOAYkJrq4X/OkTZjwXjQhXnDwiwacuCnqLpDz4OX1Nr7EKJz1ZzmGrw==","P":"7zjThXlm/qG07URGqKTnq1QWGwoCCxXfVK5u0xbzhuPtjISAk2ijs4Bp7XNbQD63zdO52k7F8od8s4HXBjCG5rzpMNxpMef3SPfBX2f726XtQQYhXEW90iXeIUl55Hp41M+CO9GQs4XOy+k/AtkDbbaR7EKAQP7w4ddhRSJUyqM=","Q":"2LYnkzwnZdd4Femjg/6whVLFJZ8g78dew/0SnlX++3ShOX9GheACcunKVs6LD8X9ALay2ondx+4qRuep0wphc4UK6HoN9S/GnhJZDt2GjfAPPPegEfOEW+jIcX/COYX1unfcCVb17Cl+dWfQRa6RXtvfputA1u6N+wb0wtcmwIU="}}