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 AspNet.Security.OAuth.Validation; |
||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Identity; |
||||
using Microsoft.AspNetCore.Mvc; |
using Microsoft.AspNetCore.Mvc; |
||||
|
using Mvc.Server.Models; |
||||
|
|
||||
namespace Mvc.Server.Controllers { |
namespace Mvc.Server.Controllers { |
||||
[Route("api")] |
[Route("api")] |
||||
public class ResourceController : Controller { |
public class ResourceController : Controller { |
||||
|
private readonly UserManager<ApplicationUser> _userManager; |
||||
|
|
||||
|
public ResourceController(UserManager<ApplicationUser> userManager) { |
||||
|
_userManager = userManager; |
||||
|
} |
||||
|
|
||||
[Authorize(ActiveAuthenticationSchemes = OAuthValidationDefaults.AuthenticationScheme)] |
[Authorize(ActiveAuthenticationSchemes = OAuthValidationDefaults.AuthenticationScheme)] |
||||
[HttpGet("message")] |
[HttpGet("message")] |
||||
public IActionResult GetMessage() { |
public async Task<IActionResult> GetMessage() { |
||||
var identity = User.Identity as ClaimsIdentity; |
var user = await _userManager.GetUserAsync(User); |
||||
if (identity == null) { |
if (user == null) { |
||||
return BadRequest(); |
return BadRequest(); |
||||
} |
} |
||||
|
|
||||
return Content($"{identity.Name} has been successfully authenticated."); |
return Content($"{user.UserName} has been successfully authenticated."); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
Loading…
Reference in new issue