Skip to content

Commit ae98914

Browse files
committed
Feat: ClaimsIdentityExtensions
1 parent 832f270 commit ae98914

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/CodeOfChaos.Extensions/ClaimsIdentityExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ namespace CodeOfChaos.Extensions;
99
// Code
1010
// ---------------------------------------------------------------------------------------------------------------------
1111
public static class ClaimsIdentityExtensions {
12+
13+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, Claim claim) {
14+
identity.AddClaim(claim);
15+
return identity;
16+
}
17+
18+
public static ClaimsIdentity AddClaims(this ClaimsIdentity identity, IEnumerable<Claim> claims) {
19+
identity.AddClaims(claims);
20+
return identity;
21+
}
22+
23+
public static ClaimsIdentity RemoveClaim(this ClaimsIdentity identity, Claim? claim) {
24+
identity.RemoveClaim(claim);
25+
return identity;
26+
}
27+
28+
public static IEnumerable<string> FindAllValues(this ClaimsIdentity identity, string type) {
29+
IEnumerable<Claim> claims = identity.FindAll(type);
30+
return claims.Select(c => c.Value);
31+
}
32+
1233
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value) {
1334
identity.AddClaim(new Claim(type, value));
1435
return identity;

0 commit comments

Comments
 (0)