1
+ using EAVFramework ;
1
2
using EAVFramework . Authentication ;
3
+ using EAVFramework . Endpoints ;
2
4
using EAVFramework . Extensions ;
5
+ using EAVFW . Extensions . SecurityModel ;
3
6
using IdentityModel ;
4
7
using IdentityModel . Client ;
5
8
using Microsoft . AspNetCore . Http ;
25
28
namespace EAVFW . Extensions . EasyAuth . MicrosoftEntraId
26
29
{
27
30
28
- public class MicrosoftEntraEasyAuthProvider : IEasyAuthProvider
31
+ public class MicrosoftEntraEasyAuthProvider < TSecurityGroup , TSecurityGroupMember > : IEasyAuthProvider
32
+ where TSecurityGroup : DynamicEntity , IEntraIDSecurityGroup
33
+ where TSecurityGroupMember : DynamicEntity , ISecurityGroupMember
29
34
{
30
35
private readonly IOptions < MicrosoftEntraIdEasyAuthOptions > _options ;
31
36
private readonly IHttpClientFactory _clientFactory ;
37
+ private readonly EAVDBContext < DynamicContext > _db ;
32
38
33
39
public string AuthenticationName => "MicrosoftEntraId" ;
34
40
@@ -38,10 +44,12 @@ public class MicrosoftEntraEasyAuthProvider : IEasyAuthProvider
38
44
39
45
public MicrosoftEntraEasyAuthProvider ( ) { }
40
46
41
- public MicrosoftEntraEasyAuthProvider ( IOptions < MicrosoftEntraIdEasyAuthOptions > options , IHttpClientFactory clientFactory )
47
+ public MicrosoftEntraEasyAuthProvider ( IOptions < MicrosoftEntraIdEasyAuthOptions > options ,
48
+ IHttpClientFactory clientFactory , EAVDBContext < DynamicContext > db )
42
49
{
43
50
_options = options ?? throw new System . ArgumentNullException ( nameof ( options ) ) ;
44
51
_clientFactory = clientFactory ?? throw new ArgumentNullException ( nameof ( clientFactory ) ) ;
52
+ _db = db ;
45
53
}
46
54
47
55
public async Task OnAuthenticate ( HttpContext httpcontext , string handleId , string redirectUrl )
@@ -86,6 +94,27 @@ public async Task OnAuthenticate(HttpContext httpcontext, string handleId, strin
86
94
httpcontext . Response . Redirect ( $ "{ httpcontext . Request . Scheme } ://{ httpcontext . Request . Host } callback?error=access_denied&error_subcode=user_not_found") ;
87
95
//return;
88
96
}
97
+
98
+ var handler = new JwtSecurityTokenHandler ( ) ;
99
+ var jwtSecurityToken = handler . ReadJwtToken ( response . IdentityToken ) ;
100
+
101
+ var groupId = jwtSecurityToken . Claims . First ( claim => claim . Type == "groups" ) . Value ;
102
+
103
+ var groupids = new string [ ] { "" , "" } ;
104
+
105
+ var sgs = _db . Set < TSecurityGroup > ( ) ;
106
+ var assignments = _db . Set < TSecurityGroupMember > ( ) ;
107
+
108
+
109
+ //Add securityMember for the group ids where found
110
+
111
+
112
+ //Remove securirymember from existing that was not given in groupids.
113
+
114
+
115
+
116
+
117
+
89
118
return await Task . FromResult ( ( new ClaimsPrincipal ( identity ) , redirectUri , handleId ) ) ;
90
119
}
91
120
0 commit comments