File tree Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public enum AuthenticationMode
15
15
ActiveDirectory ,
16
16
ActiveDirectorySingleUser ,
17
17
ThirdPartyProvider ,
18
+ Impersonate ,
18
19
NotDefined
19
20
} ;
20
21
@@ -36,7 +37,8 @@ public static NetworkCredential NetworkCredential()
36
37
37
38
public static AuthenticationMode GetAuthenticationMode ( )
38
39
{
39
- if ( Int32 . TryParse ( ConfigurationManager . AppSettings [ "API_AUTH_MODE" ] , out int mode ) )
40
+ int mode = 0 ;
41
+ if ( Int32 . TryParse ( ConfigurationManager . AppSettings [ "API_AUTH_MODE" ] , out mode ) )
40
42
{
41
43
switch ( mode )
42
44
{
@@ -46,6 +48,8 @@ public static AuthenticationMode GetAuthenticationMode()
46
48
return AuthenticationMode . ActiveDirectorySingleUser ;
47
49
case 3 :
48
50
return AuthenticationMode . ThirdPartyProvider ;
51
+ case 4 :
52
+ return AuthenticationMode . Impersonate ;
49
53
default :
50
54
return AuthenticationMode . NotDefined ;
51
55
}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
20
20
break ;
21
21
case ServiceConfig . AuthenticationMode . ActiveDirectorySingleUser :
22
22
case ServiceConfig . AuthenticationMode . ThirdPartyProvider :
23
+ case ServiceConfig . AuthenticationMode . Impersonate :
23
24
identity = ServiceConfig . ParseUserCredential ( ) ;
24
25
break ;
25
26
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Web ;
3
+ using System . Configuration ;
4
+ using System . Net . Mail ;
5
+ using System . Security . Principal ;
6
+ using System . Security . Claims ;
3
7
4
8
namespace AxaptaApiApp . Utils
5
9
{
@@ -46,6 +50,23 @@ public static class ClientFactory
46
50
HttpContext . Current . User . Identity . AuthenticationType ,
47
51
HttpContext . Current . User . Identity . Name ) ;
48
52
}
53
+ else if ( ServiceConfig . GetAuthenticationMode ( ) == ServiceConfig . AuthenticationMode . Impersonate )
54
+ {
55
+ string domain = HttpContext . Current . User . Identity . AuthenticationType ;
56
+ string username = "" ;
57
+ ClaimsPrincipal claimsPrincipal = HttpContext . Current . User as ClaimsPrincipal ;
58
+ string email = claimsPrincipal . FindFirst ( ClaimTypes . Upn ) != null ? claimsPrincipal . FindFirst ( ClaimTypes . Upn ) . Value : claimsPrincipal . FindFirst ( ClaimTypes . Email ) . Value ;
59
+
60
+ //aad is Azure Active Directory - if aad is used then use the internal network domain name from the app settings
61
+ //Other possible values are Google, Facebook, Twitter - for those we will pass direct to AX as a claims user
62
+ if ( String . Equals ( domain , "aad" ) )
63
+ {
64
+ domain = ConfigurationManager . AppSettings [ "API_AUTH_USER_DOMAIN" ] ;
65
+ MailAddress addr = new MailAddress ( email ) ; //takes [email protected]
66
+ username = addr . User ; //returns username
67
+ }
68
+ context . LogonAsUser = String . Format ( "{0}\\ {1}" , domain , username ) ;
69
+ }
49
70
50
71
return context ;
51
72
}
Original file line number Diff line number Diff line change 7
7
8
8
Mode 1: Multi-User (Active Directory)
9
9
Mode 2: Single-User (Active Directory)
10
- Mode 3: Third-Party Provider
10
+ Mode 3: Third-Party Provider - Impersonates but takes the authenticate type and name
11
+ Mode 4: Impersonate - uses the API_AUTH_USER_DOMAIN and the username from the email to resolve a string like domain\username
12
+ - this is used usually when you are syncing your onpremise AD to Azure AD
11
13
-->
12
14
<add key =" API_AUTH_MODE" value =" 2" />
13
15
<add key =" API_AUTH_USER_DOMAIN" value =" " />
You can’t perform that action at this time.
0 commit comments