fix: 修复authservice状态问题

This commit is contained in:
橙子
2024-11-16 11:07:22 +08:00
parent 18dd177961
commit 84cd83894b

View File

@@ -20,14 +20,15 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication
/// </summary> /// </summary>
public class AuthService : YiCrudAppService<AuthAggregateRoot, AuthOutputDto, Guid, AuthGetListInput> public class AuthService : YiCrudAppService<AuthAggregateRoot, AuthOutputDto, Guid, AuthGetListInput>
{ {
private HttpContext HttpContext { get; set; } private HttpContext? HttpContext { get; set; }
private ILogger<AuthService> _logger; private ILogger<AuthService> _logger;
private ISqlSugarRepository<AuthAggregateRoot, Guid> _repository; private ISqlSugarRepository<AuthAggregateRoot, Guid> _repository;
private IAccountManager _accountManager; private IAccountManager _accountManager;
public AuthService(IAccountManager accountManager, IHttpContextAccessor httpContextAccessor, ILogger<AuthService> logger, ISqlSugarRepository<AuthAggregateRoot, Guid> repository) : base(repository) public AuthService(IAccountManager accountManager, IHttpContextAccessor httpContextAccessor, ILogger<AuthService> logger, ISqlSugarRepository<AuthAggregateRoot, Guid> repository) : base(repository)
{ {
_logger = logger; _logger = logger;
HttpContext = httpContextAccessor.HttpContext ?? throw new ApplicationException("未注册Http"); //可能为空
HttpContext = httpContextAccessor.HttpContext;
_repository = repository; _repository = repository;
_accountManager = accountManager; _accountManager = accountManager;
} }
@@ -79,6 +80,10 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication
private async Task<(string, string)> GetOpenIdAndNameAsync(string scheme) private async Task<(string, string)> GetOpenIdAndNameAsync(string scheme)
{ {
if (HttpContext is null)
{
throw new AggregateException("HttpContext 参数为空");
}
var authenticateResult = await HttpContext.AuthenticateAsync(scheme); var authenticateResult = await HttpContext.AuthenticateAsync(scheme);
if (!authenticateResult.Succeeded) if (!authenticateResult.Succeeded)
{ {