Claim Logic
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System.Security.Claims;
|
||||
using FoodsharingSiegen.Contracts;
|
||||
using FoodsharingSiegen.Server.Auth;
|
||||
using FoodsharingSiegen.Server.Data.Service;
|
||||
using FoodsharingSiegen.Shared.Helper;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
@@ -17,6 +18,8 @@ namespace FoodsharingSiegen.Server.Service
|
||||
/// <summary> LocalStorageService </summary>
|
||||
private readonly LocalStorageService _localStorageService;
|
||||
|
||||
private readonly UserService _userService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setup/Teardown
|
||||
@@ -25,7 +28,12 @@ namespace FoodsharingSiegen.Server.Service
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="localStorageService"></param>
|
||||
public TokenAuthStateProvider(LocalStorageService localStorageService) => _localStorageService = localStorageService;
|
||||
/// <param name="userService"></param>
|
||||
public TokenAuthStateProvider(LocalStorageService localStorageService, UserService userService)
|
||||
{
|
||||
_localStorageService = localStorageService;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -38,8 +46,12 @@ namespace FoodsharingSiegen.Server.Service
|
||||
public override async Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
var token = await _localStorageService.GetItem<string>(StorageKeys.TokenKey);
|
||||
var tokenValid = AuthHelper.ValidateToken(token, out _);
|
||||
var tokenValid = AuthHelper.ValidateToken(token, out var user);
|
||||
|
||||
var checkR = await _userService.CheckForceLogout(user);
|
||||
if (checkR.Success && checkR.Data)
|
||||
tokenValid = false;
|
||||
|
||||
var identity = new ClaimsIdentity();
|
||||
if (tokenValid)
|
||||
identity = new ClaimsIdentity(new[]
|
||||
|
||||
Reference in New Issue
Block a user