Skip to content

Commit 832f270

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

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using System.Security.Claims;
5+
6+
namespace CodeOfChaos.Extensions;
7+
8+
// ---------------------------------------------------------------------------------------------------------------------
9+
// Code
10+
// ---------------------------------------------------------------------------------------------------------------------
11+
public static class ClaimsIdentityExtensions {
12+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value) {
13+
identity.AddClaim(new Claim(type, value));
14+
return identity;
15+
}
16+
17+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, string? valueType) {
18+
identity.AddClaim(new Claim(type, value, valueType));
19+
return identity;
20+
}
21+
22+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, string? valueType, string? issuer) {
23+
identity.AddClaim(new Claim(type, value, valueType, issuer));
24+
return identity;
25+
}
26+
27+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, string? valueType, string? issuer, string? originalIssuer) {
28+
identity.AddClaim(new Claim(type, value, valueType, issuer, originalIssuer));
29+
return identity;
30+
}
31+
32+
public static ClaimsIdentity AddClaim(this ClaimsIdentity identity, string type, string value, string? valueType, string? issuer, string? originalIssuer, ClaimsIdentity? subject) {
33+
identity.AddClaim(new Claim(type, value, valueType, issuer, originalIssuer, subject));
34+
return identity;
35+
}
36+
}

0 commit comments

Comments
 (0)