Claim Logic
This commit is contained in:
@@ -98,6 +98,7 @@ namespace FoodsharingSiegen.Server.Auth
|
||||
{
|
||||
Name = "Andre",
|
||||
Mail = "fs@beging.de",
|
||||
GroupsList = new List<UserGroup> { UserGroup.Ambassador },
|
||||
Type = UserType.Admin,
|
||||
Created = DateTime.UtcNow,
|
||||
EncryptedPassword = "qSIxTZo7J8M="
|
||||
@@ -117,7 +118,15 @@ namespace FoodsharingSiegen.Server.Auth
|
||||
{
|
||||
var serializedToken = AuthHelper.CreateToken(_user);
|
||||
await _localStorageService.SetItem(StorageKeys.TokenKey, serializedToken);
|
||||
|
||||
|
||||
if (_user.ForceLogout)
|
||||
{
|
||||
_user.ForceLogout = false;
|
||||
await Context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
Context.Entry(_user).State = EntityState.Detached;
|
||||
|
||||
return new OperationResult();
|
||||
}
|
||||
|
||||
|
||||
@@ -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