require admin role
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-05-19 05:08:00 +02:00
parent 8347b10401
commit 8cd1e10cd7
5 changed files with 17 additions and 9 deletions

View File

@ -22,7 +22,6 @@ namespace HanyadikHetVan.Controllers.V1
}
[HttpGet("json")]
[Consumes(MediaTypeNames.Application.Json)]
[Produces(MediaTypeNames.Application.Json)]
public HanyadikHetVanDTO GetJson()
{

View File

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Net.Mime;
using System.Security.Claims;
namespace HanyadikHetVan.Controllers.V1
@ -19,7 +20,7 @@ namespace HanyadikHetVan.Controllers.V1
}
[HttpGet("unprotected")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public string Unprotected()
{
@ -28,10 +29,18 @@ namespace HanyadikHetVan.Controllers.V1
[Authorize]
[HttpGet("protected")]
[Produces("application/json")]
[Produces(MediaTypeNames.Application.Json)]
public string Protected()
{
return this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
}
[Authorize(Roles = "admin")]
[HttpGet("roleprotected")]
[Produces(MediaTypeNames.Application.Json)]
public string RoleProtected()
{
return this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
}
}
}