Files
mixtape/zero.Core/Identity/RoleStore.Claim.cs
T

38 lines
1.1 KiB
C#
Raw Normal View History

2020-04-14 20:16:04 +02:00
using Microsoft.AspNetCore.Identity;
using Raven.Client.Documents.Session;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
using zero.Core.Entities;
namespace zero.Core.Identity
{
2020-04-15 01:42:06 +02:00
public partial class RoleStore<TRole> : IRoleClaimStore<TRole> where TRole : class, IUserRole
2020-04-14 20:16:04 +02:00
{
/// <inheritdoc/>
2020-04-15 01:42:06 +02:00
public Task AddClaimAsync(TRole role, Claim claim, CancellationToken cancellationToken = default)
2020-04-14 20:16:04 +02:00
{
2020-04-15 01:42:06 +02:00
role.Claims.Add(new UserClaim(claim));
return Task.CompletedTask;
2020-04-14 20:16:04 +02:00
}
/// <inheritdoc/>
2020-04-15 01:42:06 +02:00
public Task<IList<Claim>> GetClaimsAsync(TRole role, CancellationToken cancellationToken = default)
2020-04-14 20:16:04 +02:00
{
return Task.FromResult((IList<Claim>)role.Claims.Select(claim => claim.ToClaim()).ToList());
}
/// <inheritdoc/>
2020-04-15 01:42:06 +02:00
public Task RemoveClaimAsync(TRole role, Claim claim, CancellationToken cancellationToken = default)
2020-04-14 20:16:04 +02:00
{
2020-04-15 01:42:06 +02:00
UserClaim userClaim = new UserClaim(claim);
role.Claims = role.Claims.Except(new List<UserClaim>() { userClaim }, new UserClaimComparer()).ToList();
return Task.CompletedTask;
2020-04-14 20:16:04 +02:00
}
}
}