Torma Kristóf
634488c2d8
All checks were successful
continuous-integration/drone/push Build is passing
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using HanyadikHetVan.Data.Entities;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Data;
|
|
using System.Net.Mime;
|
|
using System.Security.Claims;
|
|
|
|
namespace HanyadikHetVan.Controllers.V1
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
[ApiController]
|
|
public class TestController : Controller
|
|
{
|
|
private UserManager<User> _userManager;
|
|
|
|
public TestController(UserManager<User> userManager)
|
|
{
|
|
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
|
}
|
|
|
|
[HttpGet("unprotected")]
|
|
[Produces(MediaTypeNames.Application.Json)]
|
|
public string Unprotected()
|
|
{
|
|
|
|
return "Unprotected";
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpGet("protected")]
|
|
[Produces(MediaTypeNames.Application.Json)]
|
|
public string Protected()
|
|
{
|
|
return this.User.FindFirst(ClaimTypes.Role).Value;
|
|
}
|
|
|
|
[Authorize(Roles = "admin")]
|
|
[HttpGet("roleprotected")]
|
|
[Produces(MediaTypeNames.Application.Json)]
|
|
public string RoleProtected()
|
|
{
|
|
return this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
|
|
}
|
|
}
|
|
}
|