chore
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Atomx.Admin.Client.Models;
|
||||
using Atomx.Admin.Client.Validators;
|
||||
using Atomx.Admin.Services;
|
||||
using Atomx.Admin.Utils;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Common.Utils;
|
||||
using Atomx.Data;
|
||||
@@ -10,12 +11,15 @@ using Atomx.Data.Services;
|
||||
using Atomx.Utils.Extension;
|
||||
using MapsterMapper;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Atomx.Admin.Controllers
|
||||
{
|
||||
@@ -30,8 +34,9 @@ namespace Atomx.Admin.Controllers
|
||||
readonly DataContext _dbContext;
|
||||
readonly JwtSetting _jwtSetting;
|
||||
readonly ICacheService _cacheService;
|
||||
readonly AuthenticationStateProvider _authenticationStateProvider;
|
||||
|
||||
public SignController(ILogger<SignController> logger, IdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService)
|
||||
public SignController(ILogger<SignController> logger, IdentityService identityService, IIdCreatorService idCreator, IMapper mapper, DataContext dbContext, JwtSetting jwtSetting, ICacheService cacheService, AuthenticationStateProvider authenticationStateProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_identityService = identityService;
|
||||
@@ -40,6 +45,7 @@ namespace Atomx.Admin.Controllers
|
||||
_dbContext = dbContext;
|
||||
_jwtSetting = jwtSetting;
|
||||
_cacheService = cacheService;
|
||||
_authenticationStateProvider = authenticationStateProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,7 +54,7 @@ namespace Atomx.Admin.Controllers
|
||||
/// <returns></returns>
|
||||
[HttpPost("in")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Login(LoginModel model)
|
||||
public async Task<IActionResult> Login(LoginModel model)
|
||||
{
|
||||
var validator = new LoginModelValidator();
|
||||
var validation = validator.Validate(model);
|
||||
@@ -100,10 +106,12 @@ namespace Atomx.Admin.Controllers
|
||||
new Claim(ClaimKeys.Permission, role?.Permission??string.Empty)
|
||||
};
|
||||
|
||||
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
|
||||
var tokenDescriptor = new SecurityTokenDescriptor
|
||||
{
|
||||
Subject = new ClaimsIdentity(claims),
|
||||
Subject = claimsIdentity,
|
||||
|
||||
Expires = DateTime.UtcNow.AddMinutes(_jwtSetting.AccessTokenExpirationMinutes),
|
||||
SigningCredentials = credentials,
|
||||
@@ -119,6 +127,9 @@ namespace Atomx.Admin.Controllers
|
||||
user.LastIp = _identityService.GetClientIp();
|
||||
user.LoginCount++;
|
||||
|
||||
//((PersistingRevalidatingAuthenticationStateProvider) _authenticationStateProvider).
|
||||
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
|
||||
return new JsonResult(loginResult);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user