38 lines
982 B
C#
38 lines
982 B
C#
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
using Microsoft.AspNetCore.Identity;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using System;
|
|||
|
using System.Security.Claims;
|
|||
|
|
|||
|
namespace HanyadikHetVan.Controllers.V1
|
|||
|
{
|
|||
|
[ApiVersion("1.0")]
|
|||
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|||
|
[ApiController]
|
|||
|
public class TestController : Controller
|
|||
|
{
|
|||
|
private UserManager<IdentityUser> _userManager;
|
|||
|
|
|||
|
public TestController(UserManager<IdentityUser> userManager)
|
|||
|
{
|
|||
|
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
|||
|
}
|
|||
|
|
|||
|
[HttpGet("unprotected")]
|
|||
|
[Produces("application/json")]
|
|||
|
public string Unprotected()
|
|||
|
{
|
|||
|
|
|||
|
return "Unprotected";
|
|||
|
}
|
|||
|
|
|||
|
[Authorize]
|
|||
|
[HttpGet("protected")]
|
|||
|
[Produces("application/json")]
|
|||
|
public string Protected()
|
|||
|
{
|
|||
|
return this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|