-
Notifications
You must be signed in to change notification settings - Fork 65
/
CustomClaimProvider.cs
56 lines (46 loc) · 1.33 KB
/
CustomClaimProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using cloudscribe.Core.Models;
using System.Security.Claims;
using Microsoft.Extensions.Options;
using cloudscribe.Core.Identity;
namespace cloudscribe.Core.SimpleContent.Integration
{
public class CustomClaimProvider : ICustomClaimProvider
{
public CustomClaimProvider(
IOptions<List<CustomClaimMap>> claimMapsAccessor
)
{
claimMaps = claimMapsAccessor.Value;
}
private List<CustomClaimMap> claimMaps;
public Task AddClaims(SiteUser user, ClaimsIdentity identity)
{
foreach(var map in claimMaps)
{
if(map.UserEmail == user.Email)
{
foreach(var c in map.Claims)
{
identity.AddClaim(new Claim(c.ClaimType, c.ClaimValue));
}
}
}
return Task.FromResult(0);
}
}
public class CustomClaimMap
{
public string UserEmail { get; set; }
public List<CustomClaim> Claims { get; set; }
}
public class CustomClaim
{
public string ClaimType { get; set; }
public string ClaimValue { get; set; }
}
}