JWT symmetric keys #77

Merged
kdeng00 merged 6 commits from jwt_symmetric_keys into v0.1.20 2022-09-04 20:58:13 -04:00
11 changed files with 7 additions and 128 deletions
Showing only changes of commit 05b5de0939 - Show all commits
-3
View File
@@ -253,11 +253,8 @@ namespace Icarus.Controllers.Managers
var claim = new List<System.Security.Claims.Claim>()
{
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("aud", $"{audience}", "string"),
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 Claim(JwtRegisteredClaimNames.Sub, subject),
new System.Security.Claims.Claim(JwtRegisteredClaimNames.Iat, currentDate.ToString())
+1 -10
View File
@@ -14,6 +14,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/album")]
[ApiController]
[Authorize]
public class AlbumController : BaseController
{
#region Fields
@@ -40,11 +41,6 @@ namespace Icarus.Controllers.V1
[HttpGet]
public IActionResult Get()
{
if (!IsTokenValid("read:albums"))
{
return StatusCode(401, "Not allowed");
}
List<Album> albums = new List<Album>();
var albumContext = new AlbumContext(_connectionString);
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{id}")]
public IActionResult Get(int id)
{
if (!IsTokenValid("read:albums"))
{
return StatusCode(401, "Not allowed");
}
Album album = new Album
{
AlbumID = id
+1 -5
View File
@@ -13,6 +13,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/artist")]
[ApiController]
[Authorize]
public class ArtistController : BaseController
{
#region Fields
@@ -39,11 +40,6 @@ namespace Icarus.Controllers.V1
[HttpGet]
public IActionResult Get()
{
if (!IsTokenValid("read:artists"))
{
return StatusCode(401, "Not allowed");
}
var artistContext = new ArtistContext(_connectionString);
var artists = artistContext.Artists.ToList();
+1 -10
View File
@@ -15,6 +15,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/coverart")]
[ApiController]
[Authorize]
public class CoverArtController : BaseController
{
#region Fields
@@ -36,11 +37,6 @@ namespace Icarus.Controllers.V1
#region HTTP Routes
public IActionResult Get()
{
if (!IsTokenValid("read:songs"))
{
return StatusCode(401, "Not allowed");
}
var coverArtContext = new CoverArtContext(_connectionString);
var coverArtRecords = coverArtContext.CoverArtImages.ToList();
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{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 coverArtContext = new CoverArtContext(_connectionString);
+1 -10
View File
@@ -14,6 +14,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/genre")]
[ApiController]
[Authorize]
public class GenreController : BaseController
{
#region Fields
@@ -40,11 +41,6 @@ namespace Icarus.Controllers.V1
[HttpGet]
public IActionResult Get()
{
if (!IsTokenValid("read:genre"))
{
return StatusCode(401, "Not allowed");
}
var genres = new List<Genre>();
var genreStore = new GenreContext(_connectionString);
@@ -60,11 +56,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{id}")]
public IActionResult Get(int id)
{
if (!IsTokenValid("read:genre"))
{
return StatusCode(401, "Not allowed");
}
var genre = new Genre
{
GenreID = id
-4
View File
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
@@ -75,7 +72,6 @@ namespace Icarus.Controllers.V1
TokenManager tk = new TokenManager(_config);
// loginRes = tk.LogIn(user);
loginRes = tk.LoginSymmetric(user);
return Ok(loginRes);
@@ -19,6 +19,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/song/compressed/data")]
[ApiController]
[Authorize]
public class SongCompressedDataController : BaseController
{
#region Fields
@@ -47,11 +48,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
if (!IsTokenValid("download:songs"))
{
return StatusCode(401, "Not allowed");
}
var context = new SongContext(_connectionString);
SongCompression cmp = new SongCompression(_archiveDir);
+1 -15
View File
@@ -18,6 +18,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/song")]
[ApiController]
[Authorize]
public class SongController : BaseController
{
#region Fields
@@ -49,11 +50,6 @@ namespace Icarus.Controllers.V1
[HttpGet]
public IActionResult Get()
{
if (!IsTokenValid("read:song_details"))
{
return StatusCode(401, "Not allowed");
}
List<Song> songs = new List<Song>();
Console.WriteLine("Attemtping to retrieve songs");
_logger.LogInformation("Attempting to retrieve songs");
@@ -71,11 +67,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{id}")]
public IActionResult Get(int id)
{
if (!IsTokenValid("read:song_details"))
{
return StatusCode(401, "Not allowed");
}
var context = new SongContext(_connectionString);
Song song = new Song { SongID = id };
@@ -92,11 +83,6 @@ namespace Icarus.Controllers.V1
[HttpPut("{id}")]
public IActionResult Put(int id, [FromBody] Song song)
{
if (!IsTokenValid("update:songs"))
{
return StatusCode(401, "Not allowed");
}
var context = new SongContext(_connectionString);
song.SongID = id;
+1 -20
View File
@@ -20,6 +20,7 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/song/data")]
[ApiController]
[Authorize]
public class SongDataController : BaseController
{
#region Fields
@@ -50,11 +51,6 @@ namespace Icarus.Controllers.V1
[Route("private-scoped")]
public async Task<IActionResult> Get(int id)
{
if (!IsTokenValid("download:songs"))
{
return StatusCode(401, "Not allowed");
}
var songContext = new SongContext(_connectionString);
var songMetaData = songContext.RetrieveRecord(new Song { SongID = id});
@@ -79,11 +75,6 @@ namespace Icarus.Controllers.V1
[Route("private-scoped")]
public IActionResult Post([FromForm(Name = "file")] List<IFormFile> songData)
{
if (!IsTokenValid("upload:songs"))
{
return StatusCode(401, "Not allowed");
}
try
{
// Console.WriteLine("Uploading song...");
@@ -121,11 +112,6 @@ namespace Icarus.Controllers.V1
[Route("private-scoped")]
public IActionResult Post ([FromForm] UploadSongWithDataForm up)
{
if (!IsTokenValid("upload:songs"))
{
return StatusCode(401, "Not allowed");
}
try
{
if (up.SongData.Length > 0 && up.CoverArtData.Length > 0 && !string.IsNullOrEmpty(up.SongFile))
@@ -147,11 +133,6 @@ namespace Icarus.Controllers.V1
[HttpDelete("delete/{id}")]
public IActionResult Delete(int id)
{
if (!IsTokenValid("delete:songs"))
{
return StatusCode(401, "Not allowed");
}
var songContext = new SongContext(_connectionString);
var songMetaData = new Song{ SongID = id };
-7
View File
@@ -47,13 +47,6 @@ namespace Icarus.Controllers.V1
[HttpGet("{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 song = context.Songs.FirstOrDefault(sng => sng.SongID == id);
-39
View File
@@ -19,35 +19,6 @@ using Icarus.Database.Contexts;
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
{
#region Constructors
@@ -95,16 +66,6 @@ namespace Icarus
services.AddDbContext<GenreContext>(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()
.AddNewtonsoftJson();
}