V0.1.20 #80
@@ -253,11 +253,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var claim = new List<System.Security.Claims.Claim>()
|
var claim = new List<System.Security.Claims.Claim>()
|
||||||
{
|
{
|
||||||
new System.Security.Claims.Claim("scope", AllScopes(), "string"),
|
new System.Security.Claims.Claim("scope", AllScopes(), "string"),
|
||||||
// new System.Security.Claims.Claim("exp", $"{expires}", "integer"),
|
|
||||||
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Exp, expiredDate.ToString()),
|
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Exp, expiredDate.ToString()),
|
||||||
// new System.Security.Claims.Claim("aud", $"{audience}", "string"),
|
|
||||||
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Aud, audience),
|
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Aud, audience),
|
||||||
// new System.Security.Claims.Claim("iss", $"{issuer}", "string"),
|
|
||||||
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iss, issuer),
|
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iss, issuer),
|
||||||
new Claim(JwtRegisteredClaimNames.Sub, subject),
|
new Claim(JwtRegisteredClaimNames.Sub, subject),
|
||||||
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iat, currentDate.ToString())
|
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iat, currentDate.ToString())
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/album")]
|
[Route("api/v1/album")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class AlbumController : BaseController
|
public class AlbumController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -40,11 +41,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:albums"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Album> albums = new List<Album>();
|
List<Album> albums = new List<Album>();
|
||||||
|
|
||||||
var albumContext = new AlbumContext(_connectionString);
|
var albumContext = new AlbumContext(_connectionString);
|
||||||
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:albums"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
Album album = new Album
|
Album album = new Album
|
||||||
{
|
{
|
||||||
AlbumID = id
|
AlbumID = id
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/artist")]
|
[Route("api/v1/artist")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class ArtistController : BaseController
|
public class ArtistController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -39,11 +40,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:artists"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var artistContext = new ArtistContext(_connectionString);
|
var artistContext = new ArtistContext(_connectionString);
|
||||||
|
|
||||||
var artists = artistContext.Artists.ToList();
|
var artists = artistContext.Artists.ToList();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/coverart")]
|
[Route("api/v1/coverart")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class CoverArtController : BaseController
|
public class CoverArtController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -36,11 +37,6 @@ namespace Icarus.Controllers.V1
|
|||||||
#region HTTP Routes
|
#region HTTP Routes
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var coverArtContext = new CoverArtContext(_connectionString);
|
var coverArtContext = new CoverArtContext(_connectionString);
|
||||||
|
|
||||||
var coverArtRecords = coverArtContext.CoverArtImages.ToList();
|
var coverArtRecords = coverArtContext.CoverArtImages.ToList();
|
||||||
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("download:cover_art"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var coverArt = new CoverArt { CoverArtID = id };
|
var coverArt = new CoverArt { CoverArtID = id };
|
||||||
|
|
||||||
var coverArtContext = new CoverArtContext(_connectionString);
|
var coverArtContext = new CoverArtContext(_connectionString);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/genre")]
|
[Route("api/v1/genre")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class GenreController : BaseController
|
public class GenreController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -40,11 +41,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:genre"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var genres = new List<Genre>();
|
var genres = new List<Genre>();
|
||||||
|
|
||||||
var genreStore = new GenreContext(_connectionString);
|
var genreStore = new GenreContext(_connectionString);
|
||||||
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:genre"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var genre = new Genre
|
var genre = new Genre
|
||||||
{
|
{
|
||||||
GenreID = id
|
GenreID = id
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -75,7 +72,6 @@ namespace Icarus.Controllers.V1
|
|||||||
|
|
||||||
TokenManager tk = new TokenManager(_config);
|
TokenManager tk = new TokenManager(_config);
|
||||||
|
|
||||||
// loginRes = tk.LogIn(user);
|
|
||||||
loginRes = tk.LoginSymmetric(user);
|
loginRes = tk.LoginSymmetric(user);
|
||||||
|
|
||||||
return Ok(loginRes);
|
return Ok(loginRes);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/song/compressed/data")]
|
[Route("api/v1/song/compressed/data")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class SongCompressedDataController : BaseController
|
public class SongCompressedDataController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -47,11 +48,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("download:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var context = new SongContext(_connectionString);
|
var context = new SongContext(_connectionString);
|
||||||
|
|
||||||
SongCompression cmp = new SongCompression(_archiveDir);
|
SongCompression cmp = new SongCompression(_archiveDir);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/song")]
|
[Route("api/v1/song")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class SongController : BaseController
|
public class SongController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -49,11 +50,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Get()
|
public IActionResult Get()
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:song_details"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Song> songs = new List<Song>();
|
List<Song> songs = new List<Song>();
|
||||||
Console.WriteLine("Attemtping to retrieve songs");
|
Console.WriteLine("Attemtping to retrieve songs");
|
||||||
_logger.LogInformation("Attempting to retrieve songs");
|
_logger.LogInformation("Attempting to retrieve songs");
|
||||||
@@ -71,11 +67,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public IActionResult Get(int id)
|
public IActionResult Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("read:song_details"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var context = new SongContext(_connectionString);
|
var context = new SongContext(_connectionString);
|
||||||
|
|
||||||
Song song = new Song { SongID = id };
|
Song song = new Song { SongID = id };
|
||||||
@@ -92,11 +83,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpPut("{id}")]
|
[HttpPut("{id}")]
|
||||||
public IActionResult Put(int id, [FromBody] Song song)
|
public IActionResult Put(int id, [FromBody] Song song)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("update:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var context = new SongContext(_connectionString);
|
var context = new SongContext(_connectionString);
|
||||||
|
|
||||||
song.SongID = id;
|
song.SongID = id;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace Icarus.Controllers.V1
|
|||||||
{
|
{
|
||||||
[Route("api/v1/song/data")]
|
[Route("api/v1/song/data")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
public class SongDataController : BaseController
|
public class SongDataController : BaseController
|
||||||
{
|
{
|
||||||
#region Fields
|
#region Fields
|
||||||
@@ -50,11 +51,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[Route("private-scoped")]
|
[Route("private-scoped")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("download:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var songContext = new SongContext(_connectionString);
|
var songContext = new SongContext(_connectionString);
|
||||||
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
|
||||||
|
|
||||||
@@ -79,11 +75,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[Route("private-scoped")]
|
[Route("private-scoped")]
|
||||||
public IActionResult Post([FromForm(Name = "file")] List<IFormFile> songData)
|
public IActionResult Post([FromForm(Name = "file")] List<IFormFile> songData)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("upload:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Console.WriteLine("Uploading song...");
|
// Console.WriteLine("Uploading song...");
|
||||||
@@ -121,11 +112,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[Route("private-scoped")]
|
[Route("private-scoped")]
|
||||||
public IActionResult Post ([FromForm] UploadSongWithDataForm up)
|
public IActionResult Post ([FromForm] UploadSongWithDataForm up)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("upload:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile))
|
if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile))
|
||||||
@@ -147,11 +133,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpDelete("delete/{id}")]
|
[HttpDelete("delete/{id}")]
|
||||||
public IActionResult Delete(int id)
|
public IActionResult Delete(int id)
|
||||||
{
|
{
|
||||||
if (!IsTokenValid("delete:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
var songContext = new SongContext(_connectionString);
|
var songContext = new SongContext(_connectionString);
|
||||||
|
|
||||||
var songMetaData = new Song{ SongID = id };
|
var songMetaData = new Song{ SongID = id };
|
||||||
|
|||||||
@@ -47,13 +47,6 @@ namespace Icarus.Controllers.V1
|
|||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
public async Task<IActionResult> Get(int id)
|
public async Task<IActionResult> Get(int id)
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
if (!IsTokenValid("stream:songs"))
|
|
||||||
{
|
|
||||||
return StatusCode(401, "Not allowed");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
var context = new SongContext(_config.GetConnectionString("DefaultConnection"));
|
var context = new SongContext(_config.GetConnectionString("DefaultConnection"));
|
||||||
|
|
||||||
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
var song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
|
||||||
|
|||||||
-39
@@ -19,35 +19,6 @@ using Icarus.Database.Contexts;
|
|||||||
|
|
||||||
namespace Icarus
|
namespace Icarus
|
||||||
{
|
{
|
||||||
public static class ServiceStartup
|
|
||||||
{
|
|
||||||
public static IServiceCollection AddAsymmetricAuthentication(this IServiceCollection services, IConfiguration configuration)
|
|
||||||
{
|
|
||||||
var issuerSigningCertificate = new Icarus.Certs.SigningIssuerCertificate();
|
|
||||||
RsaSecurityKey issuerSigningKey = issuerSigningCertificate.GetIssuerSigningKey(configuration["RSAKeys:PublicKeyPath"]);
|
|
||||||
|
|
||||||
services.AddAuthentication(authOptions =>
|
|
||||||
{
|
|
||||||
})
|
|
||||||
.AddJwtBearer(options =>
|
|
||||||
{
|
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
|
||||||
{
|
|
||||||
IssuerSigningKey = issuerSigningKey,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool LifetimeValidator(DateTime? notBefore,
|
|
||||||
DateTime? expires,
|
|
||||||
SecurityToken securityToken,
|
|
||||||
TokenValidationParameters validationParameters)
|
|
||||||
{
|
|
||||||
return expires != null && expires > DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@@ -95,16 +66,6 @@ namespace Icarus
|
|||||||
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<GenreContext>(options => options.UseMySQL(connString));
|
||||||
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
services.AddDbContext<CoverArtContext>(options => options.UseMySQL(connString));
|
||||||
|
|
||||||
// services.AddAsymmetricAuthentication(Configuration);
|
|
||||||
|
|
||||||
/**
|
|
||||||
services.AddTransient<AuthenticationService>(au => new AuthenticationService(new UserService(Configuration), new TokenService(Configuration), Configuration));
|
|
||||||
services.AddTransient<UserService>(us => new UserService(Configuration));
|
|
||||||
services.AddTransient<TokenService>(tk => new TokenService(Configuration));
|
|
||||||
services.AddTransient<UserRepository>();
|
|
||||||
services.AddTransient<UserContext>(uc => new UserContext(connString));
|
|
||||||
*/
|
|
||||||
|
|
||||||
services.AddControllers()
|
services.AddControllers()
|
||||||
.AddNewtonsoftJson();
|
.AddNewtonsoftJson();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user