Cleaning up code convention inconsistencies
This commit is contained in:
@@ -10,16 +10,15 @@ namespace Icarus.Authorization.Handlers
|
|||||||
{
|
{
|
||||||
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
|
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement>
|
||||||
{
|
{
|
||||||
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
|
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement)
|
||||||
HasScopeRequirement requirement)
|
|
||||||
{
|
{
|
||||||
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
|
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer))
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var scopes = context.User.FindFirst(c => c.Type == "scope" &&
|
var scopes = context.User.FindFirst(c =>
|
||||||
c.Issuer == requirement.Issuer).Value.Split(' ');
|
c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' ');
|
||||||
|
|
||||||
if (scopes.Any(s => s == requirement.Scope))
|
if (scopes.Any(s => s == requirement.Scope))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Album> Albums { get; set; }
|
public DbSet<Album> Albums { get; set; }
|
||||||
|
|
||||||
public AlbumContext(DbContextOptions<AlbumContext> options)
|
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Artist> Artists { get; set; }
|
public DbSet<Artist> Artists { get; set; }
|
||||||
|
|
||||||
public ArtistContext(DbContextOptions<ArtistContext> options)
|
public ArtistContext(DbContextOptions<ArtistContext> options) : base (options) { }
|
||||||
: base (options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public class GenreContext : DbContext
|
public class GenreContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<Genre> Genres { get; set; }
|
public DbSet<Genre> Genres { get; set; }
|
||||||
|
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
|
||||||
public GenreContext(DbContextOptions<GenreContext> options)
|
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public DbSet<Song> Songs { get; set; }
|
public DbSet<Song> Songs { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public SongContext(DbContextOptions<SongContext> options)
|
public SongContext(DbContextOptions<SongContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Icarus.Database.Contexts
|
|||||||
public DbSet<User> Users { get; set; }
|
public DbSet<User> Users { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public UserContext(DbContextOptions<UserContext> options)
|
public UserContext(DbContextOptions<UserContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ namespace Icarus.Database.Contexts
|
|||||||
{
|
{
|
||||||
public DbSet<Year> YearValues { get; set; }
|
public DbSet<Year> YearValues { get; set; }
|
||||||
|
|
||||||
public YearContext(DbContextOptions<YearContext> options)
|
public YearContext(DbContextOptions<YearContext> options) : base(options) { }
|
||||||
: base(options)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-2
@@ -35,8 +35,7 @@ namespace Icarus
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>()
|
||||||
.UseStartup<Startup>()
|
|
||||||
.UseUrls("http://localhost:5002")
|
.UseUrls("http://localhost:5002")
|
||||||
.ConfigureLogging(logging =>
|
.ConfigureLogging(logging =>
|
||||||
{
|
{
|
||||||
|
|||||||
+19
-34
@@ -59,53 +59,43 @@ namespace Icarus
|
|||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
{
|
{
|
||||||
options.AddPolicy("download:songs", policy =>
|
options.AddPolicy("download:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("download:songs", domain)));
|
.Add(new HasScopeRequirement("download:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("upload:songs", policy =>
|
options.AddPolicy("upload:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("upload:songs", domain)));
|
.Add(new HasScopeRequirement("upload:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("delete:songs", policy =>
|
options.AddPolicy("delete:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("delete:songs", domain)));
|
.Add(new HasScopeRequirement("delete:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:song_details", policy =>
|
options.AddPolicy("read:song_details", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:song_details", domain)));
|
.Add(new HasScopeRequirement("read:song_details", domain)));
|
||||||
|
|
||||||
options.AddPolicy("update:songs", policy =>
|
options.AddPolicy("update:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("update:songs", domain)));
|
.Add(new HasScopeRequirement("update:songs", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:artists", policy =>
|
options.AddPolicy("read:artists", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:artists", domain)));
|
.Add(new HasScopeRequirement("read:artists", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:albums", policy =>
|
options.AddPolicy("read:albums", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:albums", domain)));
|
.Add(new HasScopeRequirement("read:albums", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:genre", policy =>
|
options.AddPolicy("read:genre", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:genre", domain)));
|
.Add(new HasScopeRequirement("read:genre", domain)));
|
||||||
|
|
||||||
options.AddPolicy("read:year", policy =>
|
options.AddPolicy("read:year", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("read:year", domain)));
|
.Add(new HasScopeRequirement("read:year", domain)));
|
||||||
|
|
||||||
options.AddPolicy("stream:songs", policy =>
|
options.AddPolicy("stream:songs", policy =>
|
||||||
policy
|
policy.Requirements
|
||||||
.Requirements
|
|
||||||
.Add(new HasScopeRequirement("stream:songs", domain)));
|
.Add(new HasScopeRequirement("stream:songs", domain)));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -115,28 +105,22 @@ namespace Icarus
|
|||||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
||||||
new SongRepository(Configuration
|
new SongRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
||||||
new AlbumRepository(Configuration
|
new AlbumRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
||||||
new ArtistRepository(Configuration
|
new ArtistRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
||||||
new GenreRepository(Configuration
|
new GenreRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
||||||
new YearRepository(Configuration
|
new YearRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
||||||
new UserRepository(Configuration
|
new UserRepository(Configuration.GetConnectionString("DefaultConnection"))));
|
||||||
.GetConnectionString("DefaultConnection"))));
|
|
||||||
|
|
||||||
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<SongContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<AlbumContext>(options => options.UseMySQL(connString));
|
||||||
@@ -146,7 +130,7 @@ namespace Icarus
|
|||||||
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// Called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
@@ -155,7 +139,8 @@ namespace Icarus
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// The default HSTS value is 30 days.
|
||||||
|
// You may want to change this for production scenarios
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user