mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Starting to create a logging system
This commit is contained in:
parent
ec74c8ef0f
commit
f081c1cf66
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using IdentityServer4.EntityFramework.DbContexts;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
@ -20,6 +21,8 @@ namespace Kyoo.Controllers
|
|||||||
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
|
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
|
||||||
{
|
{
|
||||||
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.EnsureCreated();
|
serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.EnsureCreated();
|
||||||
|
serviceScope.ServiceProvider.GetService<ConfigurationDbContext>().Database.EnsureCreated();
|
||||||
|
serviceScope.ServiceProvider.GetService<PersistedGrantDbContext>().Database.EnsureCreated();
|
||||||
// Use the next line if the database is not SQLite (SQLite doesn't support complexe migrations).
|
// Use the next line if the database is not SQLite (SQLite doesn't support complexe migrations).
|
||||||
// serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();;
|
// serviceScope.ServiceProvider.GetService<DatabaseContext>().Database.Migrate();;
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ namespace Kyoo
|
|||||||
{
|
{
|
||||||
public class DatabaseContext : DbContext
|
public class DatabaseContext : DbContext
|
||||||
{
|
{
|
||||||
public DatabaseContext(DbContextOptions options) : base(options) { }
|
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
||||||
|
|
||||||
public DbSet<Library> Libraries { get; set; }
|
public DbSet<Library> Libraries { get; set; }
|
||||||
public DbSet<Collection> Collections { get; set; }
|
public DbSet<Collection> Collections { get; set; }
|
||||||
|
47
Kyoo/IdentityContext.cs
Normal file
47
Kyoo/IdentityContext.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
|
||||||
|
namespace Kyoo
|
||||||
|
{
|
||||||
|
public class IdentityContext
|
||||||
|
{
|
||||||
|
public static IEnumerable<IdentityResource> GetIdentityResources()
|
||||||
|
{
|
||||||
|
return new List<IdentityResource>
|
||||||
|
{
|
||||||
|
new IdentityResources.OpenId(),
|
||||||
|
new IdentityResources.Email(),
|
||||||
|
new IdentityResources.Profile()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<ApiResource> GetApis()
|
||||||
|
{
|
||||||
|
return new[]
|
||||||
|
{
|
||||||
|
new ApiResource
|
||||||
|
{
|
||||||
|
Name = "Kyoo",
|
||||||
|
Scopes =
|
||||||
|
{
|
||||||
|
new Scope
|
||||||
|
{
|
||||||
|
Name = "kyoo.read",
|
||||||
|
DisplayName = "Read only access to the API.",
|
||||||
|
},
|
||||||
|
new Scope
|
||||||
|
{
|
||||||
|
Name = "kyoo.write",
|
||||||
|
DisplayName = "Read and write access to the public API"
|
||||||
|
},
|
||||||
|
new Scope
|
||||||
|
{
|
||||||
|
Name = "kyoo.admin",
|
||||||
|
DisplayName = "Full access to the admin's API and the public API."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
<PackageReference Include="IdentityServer4" Version="3.1.2" />
|
<PackageReference Include="IdentityServer4" Version="3.1.2" />
|
||||||
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.2" />
|
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.2" />
|
||||||
|
<PackageReference Include="IdentityServer4.EntityFramework" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.1.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.2" />
|
||||||
@ -88,6 +89,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="CreatePluginFolder" AfterTargets="Build">
|
<Target Name="CreatePluginFolder" AfterTargets="Build">
|
||||||
<MakeDir Directories="$(OutputPath)/plugins"/>
|
<MakeDir Directories="$(OutputPath)/plugins" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using IdentityServer4.EntityFramework.DbContexts;
|
||||||
|
using IdentityServer4.Models;
|
||||||
|
using IdentityServer4.Stores;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
@ -34,9 +38,18 @@ namespace Kyoo
|
|||||||
services.AddDbContext<DatabaseContext>(options => options.UseLazyLoadingProxies()
|
services.AddDbContext<DatabaseContext>(options => options.UseLazyLoadingProxies()
|
||||||
.UseSqlite(Configuration.GetConnectionString("Database")));
|
.UseSqlite(Configuration.GetConnectionString("Database")));
|
||||||
|
|
||||||
// services.AddIdentity<ApplicationUser, IdentityRole>()
|
services.AddIdentityServer()
|
||||||
// .AddEntityFrameworkStores()
|
.AddConfigurationStore(options =>
|
||||||
// services.AddIdentityServer();
|
{
|
||||||
|
options.ConfigureDbContext = builder => builder.UseSqlite(Configuration.GetConnectionString("Database"));
|
||||||
|
})
|
||||||
|
.AddOperationalStore(options =>
|
||||||
|
{
|
||||||
|
options.ConfigureDbContext = builder => builder.UseSqlite(Configuration.GetConnectionString("Database"));
|
||||||
|
options.EnableTokenCleanup = true;
|
||||||
|
})
|
||||||
|
.AddInMemoryIdentityResources(IdentityContext.GetIdentityResources())
|
||||||
|
.AddInMemoryApiResources(IdentityContext.GetApis());
|
||||||
|
|
||||||
services.AddScoped<ILibraryManager, LibraryManager>();
|
services.AddScoped<ILibraryManager, LibraryManager>();
|
||||||
services.AddScoped<ICrawler, Crawler>();
|
services.AddScoped<ICrawler, Crawler>();
|
||||||
@ -74,13 +87,14 @@ namespace Kyoo
|
|||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
//app.UseHttpsRedirection();
|
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
if (!env.IsDevelopment())
|
if (!env.IsDevelopment())
|
||||||
app.UseSpaStaticFiles();
|
app.UseSpaStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseIdentityServer();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
endpoints.MapControllerRoute("API Route", "api/{controller=Home}/{action=Index}/{id?}");
|
endpoints.MapControllerRoute("API Route", "api/{controller=Home}/{action=Index}/{id?}");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user