Files
podnoms/server/Controllers/BaseAuthController.cs
2018-05-09 09:48:07 +01:00

22 lines
840 B
C#

using System.Linq;
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using PodNoms.Api.Services.Auth;
[Authorize]
public class BaseAuthController : Controller {
private readonly ClaimsPrincipal _caller;
protected readonly UserManager<ApplicationUser> _userManager;
protected readonly string _userId;
protected readonly ApplicationUser _applicationUser;
public BaseAuthController(IHttpContextAccessor contextAccessor, UserManager<ApplicationUser> userManager) {
_caller = contextAccessor.HttpContext.User;
_userManager = userManager;
_userId = _caller.Claims.Single(c => c.Type == "id").Value;
_applicationUser = userManager.FindByIdAsync(_userId).Result;
}
}