32 lines
926 B
C#
32 lines
926 B
C#
using System.Security.Claims;
|
|
using Blazorise.Extensions;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
|
|
namespace NetinaShop.AdminPanel.PWA.Services;
|
|
|
|
public class CustomAuthenticationStateProvider : AuthenticationStateProvider
|
|
{
|
|
private readonly IUserUtility _userUtility;
|
|
|
|
public CustomAuthenticationStateProvider(IUserUtility userUtility)
|
|
{
|
|
_userUtility = userUtility;
|
|
}
|
|
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
|
{
|
|
var token = await _userUtility.GetBearerTokenAsync();
|
|
if (token.IsNullOrEmpty())
|
|
{
|
|
return new AuthenticationState(new());
|
|
}
|
|
var identity = new ClaimsIdentity(new[]
|
|
{
|
|
new Claim(ClaimTypes.Name, "mrfibuli"),
|
|
}, "Custom Authentication");
|
|
|
|
var user = new ClaimsPrincipal(identity);
|
|
|
|
|
|
return new AuthenticationState(user);
|
|
}
|
|
} |