Browse Source

Update ResourceController

pull/243/head
Kévin Chalet 10 years ago
parent
commit
3366eabebd
  1. 18
      samples/Mvc.Server/Controllers/ResourceController.cs

18
samples/Mvc.Server/Controllers/ResourceController.cs

@ -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…
Cancel
Save