Tokens are validated in respective endpoints

This commit is contained in:
Kun Deng
2022-08-27 21:35:49 -04:00
parent 665407aac5
commit f8ec65fd29
9 changed files with 126 additions and 115 deletions
+11 -6
View File
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
@@ -15,12 +13,11 @@ namespace Icarus.Controllers.V1
{
[Route("api/v1/artist")]
[ApiController]
public class ArtistController : ControllerBase
public class ArtistController : BaseController
{
#region Fields
private readonly ILogger<ArtistController> _logger;
private string _connectionString;
private IConfiguration _config;
#endregion
@@ -40,9 +37,13 @@ namespace Icarus.Controllers.V1
#region HTTP Routes
[HttpGet]
[Authorize("read:artists")]
public IActionResult Get()
{
if (!IsTokenValid("read:artists"))
{
return StatusCode(401, "Not allowed");
}
var artistContext = new ArtistContext(_connectionString);
var artists = artistContext.Artists.ToList();
@@ -54,9 +55,13 @@ namespace Icarus.Controllers.V1
}
[HttpGet("{id}")]
[Authorize("read:artists")]
public IActionResult Get(int id)
{
if (!IsTokenValid("read:artists"))
{
return StatusCode(401, "Not allowed");
}
Artist artist = new Artist
{
ArtistID = id