|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
using Volo.Abp.Security.Claims;
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.AspNetCore.Components.Web.Security;
|
|
|
|
|
|
|
|
|
@ -12,18 +12,16 @@ public class AbpComponentsClaimsCache : IScopedDependency
|
|
|
|
|
public ClaimsPrincipal Principal { get; private set; } = default!;
|
|
|
|
|
|
|
|
|
|
private readonly AuthenticationStateProvider? _authenticationStateProvider;
|
|
|
|
|
private readonly IAbpClaimsPrincipalFactory _abpClaimsPrincipalFactory;
|
|
|
|
|
|
|
|
|
|
public AbpComponentsClaimsCache(
|
|
|
|
|
IClientScopeServiceProviderAccessor serviceProviderAccessor)
|
|
|
|
|
{
|
|
|
|
|
_authenticationStateProvider = serviceProviderAccessor.ServiceProvider.GetService<AuthenticationStateProvider>();
|
|
|
|
|
_abpClaimsPrincipalFactory = serviceProviderAccessor.ServiceProvider.GetRequiredService<IAbpClaimsPrincipalFactory>();
|
|
|
|
|
if (_authenticationStateProvider != null)
|
|
|
|
|
{
|
|
|
|
|
_authenticationStateProvider.AuthenticationStateChanged += async (task) =>
|
|
|
|
|
{
|
|
|
|
|
Principal = await _abpClaimsPrincipalFactory.CreateDynamicAsync((await task).User);
|
|
|
|
|
Principal = (await task).User;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -34,7 +32,6 @@ public class AbpComponentsClaimsCache : IScopedDependency
|
|
|
|
|
{
|
|
|
|
|
var authenticationState = await _authenticationStateProvider.GetAuthenticationStateAsync();
|
|
|
|
|
Principal = authenticationState.User;
|
|
|
|
|
await _abpClaimsPrincipalFactory.CreateDynamicAsync(Principal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|