1 // Copyright (c) .NET Foundation. All rights reserved. 2 // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 3 4 using System.Collections.Generic; 5 using System.Security.Claims; 6 using System.Threading; 7 using System.Threading.Tasks; 8 9 namespace Microsoft.AspNetCore.Identity 10 { 11 /// <summary> 12 /// Provides an abstraction for a store of claims for a user. 13 /// </summary> 14 /// <typeparam name="TUser">The type encapsulating a user.</typeparam> 15 public interface IUserClaimStore<TUser> : IUserStore<TUser> where TUser : class 16 { 17 /// <summary> 18 /// Gets a list of <see cref="Claim"/>s to be belonging to the specified <paramref name="user"/> as an asynchronous operation. 19 /// </summary> 20 /// <param name="user">The role whose claims to retrieve.</param> 21 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> 22 /// <returns> 23 /// A <see cref="Task{TResult}"/> that represents the result of the asynchronous query, a list of <see cref="Claim"/>s. 24 /// </returns> GetClaimsAsync(TUser user, CancellationToken cancellationToken)25 Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken); 26 27 /// <summary> 28 /// Add claims to a user as an asynchronous operation. 29 /// </summary> 30 /// <param name="user">The user to add the claim to.</param> 31 /// <param name="claims">The collection of <see cref="Claim"/>s to add.</param> 32 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> 33 /// <returns>The task object representing the asynchronous operation.</returns> AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)34 Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken); 35 36 /// <summary> 37 /// Replaces the given <paramref name="claim"/> on the specified <paramref name="user"/> with the <paramref name="newClaim"/> 38 /// </summary> 39 /// <param name="user">The user to replace the claim on.</param> 40 /// <param name="claim">The claim to replace.</param> 41 /// <param name="newClaim">The new claim to replace the existing <paramref name="claim"/> with.</param> 42 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> 43 /// <returns>The task object representing the asynchronous operation.</returns> ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken)44 Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken); 45 46 /// <summary> 47 /// Removes the specified <paramref name="claims"/> from the given <paramref name="user"/>. 48 /// </summary> 49 /// <param name="user">The user to remove the specified <paramref name="claims"/> from.</param> 50 /// <param name="claims">A collection of <see cref="Claim"/>s to remove.</param> 51 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> 52 /// <returns>The task object representing the asynchronous operation.</returns> RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)53 Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken); 54 55 /// <summary> 56 /// Returns a list of users who contain the specified <see cref="Claim"/>. 57 /// </summary> 58 /// <param name="claim">The claim to look for.</param> 59 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param> 60 /// <returns> 61 /// A <see cref="Task{TResult}"/> that represents the result of the asynchronous query, a list of <typeparamref name="TUser"/> who 62 /// contain the specified claim. 63 /// </returns> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken)64 Task<IList<TUser>> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken); 65 } 66 }