Authorization functioning
This commit is contained in:
@@ -168,10 +168,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task SaveSongToFileSystem(IFormFile songFile/**, SongRepository songStore,
|
public async Task SaveSongToFileSystem(IFormFile songFile)
|
||||||
AlbumRepository albumStore, ArtistRepository artistStore,
|
|
||||||
GenreRepository genreStore, YearRepository yearStore,
|
|
||||||
CoverArtRepository coverArtStore*/)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -208,9 +205,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var coverMgr = new CoverArtManager(_config);
|
var coverMgr = new CoverArtManager(_config);
|
||||||
var coverArt = coverMgr.SaveCoverArt(song);
|
var coverArt = coverMgr.SaveCoverArt(song);
|
||||||
|
|
||||||
coverMgr.SaveCoverArtToDatabase(ref song, ref coverArt);//,
|
coverMgr.SaveCoverArtToDatabase(ref song, ref coverArt);
|
||||||
SaveSongToDatabase(song);/**, songStore, albumStore, artistStore, genreStore,
|
SaveSongToDatabase(song);
|
||||||
yearStore);*/
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -242,7 +238,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
private async Task<SongData> RetrieveSongFromFileSystem(Song details)
|
||||||
{
|
{
|
||||||
byte[] uncompressedSong = System.IO.File.ReadAllBytes(details.SongPath);
|
byte[] uncompressedSong = await System.IO.File.ReadAllBytesAsync(details.SongPath);
|
||||||
|
|
||||||
return new SongData
|
return new SongData
|
||||||
{
|
{
|
||||||
@@ -265,6 +261,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Assigning song filename");
|
_logger.Info("Assigning song filename");
|
||||||
song.Filename = songFile.FileName;
|
song.Filename = songFile.FileName;
|
||||||
|
song.DateCreated = DateTime.Now;
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace Icarus.Controllers.Utilities
|
|||||||
var archivePath = RetrieveCompressesSongPath(song);
|
var archivePath = RetrieveCompressesSongPath(song);
|
||||||
Console.WriteLine($"Compressed song saved to: {archivePath}");
|
Console.WriteLine($"Compressed song saved to: {archivePath}");
|
||||||
|
|
||||||
songData.Data = System.IO.File.ReadAllBytes(archivePath);
|
songData.Data = await System.IO.File.ReadAllBytesAsync(archivePath);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ namespace Icarus.Controllers.V1
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[Route("private-scoped")]
|
||||||
[Authorize("upload:songs")]
|
[Authorize("upload:songs")]
|
||||||
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
public async Task Post([FromForm(Name = "file")] List<IFormFile> songData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
<PackageReference Include="DotNetZip" Version="1.15.0" />
|
||||||
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
<PackageReference Include="EntityFramework" Version="6.4.4" />
|
||||||
<PackageReference Include="ID3" Version="0.6.0" />
|
<PackageReference Include="ID3" Version="0.6.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace Icarus.Models
|
|||||||
[JsonProperty("title")]
|
[JsonProperty("title")]
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
[JsonProperty("album")]
|
[JsonProperty("album")]
|
||||||
|
[Column("Album")]
|
||||||
public string AlbumTitle { get; set; }
|
public string AlbumTitle { get; set; }
|
||||||
[JsonProperty("artist")]
|
[JsonProperty("artist")]
|
||||||
public string Artist { get; set; }
|
public string Artist { get; set; }
|
||||||
@@ -25,6 +26,10 @@ namespace Icarus.Models
|
|||||||
public string Filename { get; set; }
|
public string Filename { get; set; }
|
||||||
[JsonProperty("song_path")]
|
[JsonProperty("song_path")]
|
||||||
public string SongPath { get; set; }
|
public string SongPath { get; set; }
|
||||||
|
[JsonProperty("track")]
|
||||||
|
public int Track { get; set; } = 0;
|
||||||
|
[JsonProperty("disc")]
|
||||||
|
public int Disc { get; set; } = 0;
|
||||||
|
|
||||||
// [JsonIgnore]
|
// [JsonIgnore]
|
||||||
// public Album Album { get; set; }
|
// public Album Album { get; set; }
|
||||||
|
|||||||
+10
-31
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@@ -15,6 +16,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Web;
|
using NLog.Web;
|
||||||
using NLog.Web.AspNetCore;
|
using NLog.Web.AspNetCore;
|
||||||
@@ -22,7 +24,6 @@ using NLog.Web.AspNetCore;
|
|||||||
using Icarus.Authorization;
|
using Icarus.Authorization;
|
||||||
using Icarus.Authorization.Handlers;
|
using Icarus.Authorization.Handlers;
|
||||||
using Icarus.Database.Contexts;
|
using Icarus.Database.Contexts;
|
||||||
// using Icarus.Database.Repositories;
|
|
||||||
|
|
||||||
namespace Icarus
|
namespace Icarus
|
||||||
{
|
{
|
||||||
@@ -40,16 +41,16 @@ namespace Icarus
|
|||||||
{
|
{
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
|
|
||||||
string domain = $"https://{Configuration["Auth0:Domain"]}/";
|
var auth_id = Configuration["Auth0:Domain"];
|
||||||
|
var domain = $"https://{auth_id}/";
|
||||||
|
var audience = Configuration["Auth0:ApiIdentifier"];
|
||||||
|
|
||||||
services.AddAuthentication(options =>
|
services
|
||||||
{
|
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
.AddJwtBearer(options =>
|
||||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
||||||
}).AddJwtBearer(options =>
|
|
||||||
{
|
{
|
||||||
options.Authority = domain;
|
options.Authority = domain;
|
||||||
options.Audience = Configuration["Auth0:ApiIdentifier"];
|
options.Audience = audience;
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
@@ -104,35 +105,12 @@ namespace Icarus
|
|||||||
|
|
||||||
var connString = Configuration.GetConnectionString("DefaultConnection");
|
var connString = Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
|
||||||
/**
|
|
||||||
services.Add(new ServiceDescriptor(typeof(SongRepository),
|
|
||||||
new SongRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(AlbumRepository),
|
|
||||||
new AlbumRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(ArtistRepository),
|
|
||||||
new ArtistRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(GenreRepository),
|
|
||||||
new GenreRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(YearRepository),
|
|
||||||
new YearRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(CoverArtRepository),
|
|
||||||
new CoverArtRepository(connString)));
|
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(typeof(UserRepository),
|
|
||||||
new UserRepository(connString)));
|
|
||||||
*/
|
|
||||||
|
|
||||||
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));
|
||||||
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<ArtistContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<UserContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
||||||
// services.AddDbContext<YearContext>(options => options.UseMySQL(connString));
|
|
||||||
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,6 +120,7 @@ namespace Icarus
|
|||||||
// NOTE: Dev-related configuration can be done when env.IsDevelopment() evaluated to true
|
// NOTE: Dev-related configuration can be done when env.IsDevelopment() evaluated to true
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user