1 changed files with 13 additions and 5 deletions
@ -1,20 +1,28 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using AspNet.Security.OAuth.Validation; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Identity; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Mvc.Server.Models; |
|||
|
|||
namespace Mvc.Server.Controllers { |
|||
[Route("api")] |
|||
public class ResourceController : Controller { |
|||
private readonly UserManager<ApplicationUser> _userManager; |
|||
|
|||
public ResourceController(UserManager<ApplicationUser> userManager) { |
|||
_userManager = userManager; |
|||
} |
|||
|
|||
[Authorize(ActiveAuthenticationSchemes = OAuthValidationDefaults.AuthenticationScheme)] |
|||
[HttpGet("message")] |
|||
public IActionResult GetMessage() { |
|||
var identity = User.Identity as ClaimsIdentity; |
|||
if (identity == null) { |
|||
public async Task<IActionResult> GetMessage() { |
|||
var user = await _userManager.GetUserAsync(User); |
|||
if (user == null) { |
|||
return BadRequest(); |
|||
} |
|||
|
|||
return Content($"{identity.Name} has been successfully authenticated."); |
|||
return Content($"{user.UserName} has been successfully authenticated."); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue