@@ -76,6 +76,22 @@ If a dictionary object has been passed use that object
7676
7777 public string UseMetaKey { get ; set ; }
7878
79+ public string EnableClientCert { get ; set ; }
80+
81+ public string ClientCertDirectory { get ; set ; }
82+
83+ public string ClientCertFile { get ; set ; }
84+
85+ public string ClientCertPassword { get ; set ; }
86+
87+ public string ClientId { get ; set ; }
88+
89+ public string AccessToken { get ; set ; }
90+
91+ public string RefreshToken { get ; set ; }
92+
93+ public string ClientSecret { get ; set ; }
94+
7995 public string AuthenticationType { get ; set ; }
8096
8197 public string KeyDirectory { get ; set ; }
@@ -136,6 +152,8 @@ If a dictionary object has been passed use that object
136152
137153 public bool IsJwtTokenAuthType { get ; set ; }
138154
155+ public bool IsOAuthTokenAuthType { get ; set ; }
156+
139157 public static string LogAllproperties ( MerchantConfig obj )
140158 {
141159 var hiddenProperties = Constants . HideMerchantConfigProps . Split ( ',' ) ;
@@ -170,6 +188,12 @@ private void SetValuesFromAppConfig(NameValueCollection merchantConfigSection)
170188 KeyDirectory = merchantConfigSection [ "keysDirectory" ] ;
171189 KeyfileName = merchantConfigSection [ "keyFilename" ] ;
172190 RunEnvironment = merchantConfigSection [ "runEnvironment" ] ;
191+ EnableClientCert = merchantConfigSection [ "enableClientCert" ] ;
192+ ClientCertDirectory = merchantConfigSection [ "clientCertDirectory" ] ;
193+ ClientCertFile = merchantConfigSection [ "clientCertFile" ] ;
194+ ClientCertPassword = merchantConfigSection [ "clientCertPassword" ] ;
195+ ClientId = merchantConfigSection [ "clientId" ] ;
196+ ClientSecret = merchantConfigSection [ "clientSecret" ] ;
173197 KeyAlias = merchantConfigSection [ "keyAlias" ] ;
174198 KeyPass = merchantConfigSection [ "keyPass" ] ;
175199 EnableLog = merchantConfigSection [ "enableLog" ] ;
@@ -194,25 +218,31 @@ private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantC
194218 {
195219 _propertiesSetUsing = "Dictionary Object" ;
196220
197- // MANDATORY KEYS
198- key = "merchantID" ;
199- MerchantId = merchantConfigDictionary [ key ] ;
221+ // MANDATORY KEYS
200222 key = "runEnvironment" ;
201223 RunEnvironment = merchantConfigDictionary [ key ] ;
202224 key = "authenticationType" ;
203225 AuthenticationType = merchantConfigDictionary [ key ] ;
226+
204227 key = "useMetaKey" ;
205- UseMetaKey = merchantConfigDictionary [ key ] ;
206- if ( string . IsNullOrEmpty ( UseMetaKey ) )
228+ UseMetaKey = "false" ;
229+ if ( merchantConfigDictionary . ContainsKey ( key ) )
207230 {
208- UseMetaKey = "false" ;
231+ UseMetaKey = merchantConfigDictionary [ key ] ;
232+ if ( string . IsNullOrEmpty ( UseMetaKey ) )
233+ {
234+ UseMetaKey = "false" ;
235+ }
209236 }
237+
210238
211239 Enumerations . AuthenticationType authTypeInput ;
212240 Enum . TryParse ( AuthenticationType . ToUpper ( ) , out authTypeInput ) ;
213241
214242 if ( Equals ( authTypeInput , Enumerations . AuthenticationType . HTTP_SIGNATURE ) )
215243 {
244+ key = "merchantID" ;
245+ MerchantId = merchantConfigDictionary [ key ] ;
216246 key = "merchantsecretKey" ;
217247 MerchantSecretKey = merchantConfigDictionary [ key ] ;
218248 key = "merchantKeyId" ;
@@ -233,6 +263,8 @@ private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantC
233263 // only if the key is passed read the value, otherwise use default / null values
234264 if ( Equals ( authTypeInput , Enumerations . AuthenticationType . JWT ) )
235265 {
266+ key = "merchantID" ;
267+ MerchantId = merchantConfigDictionary [ key ] ;
236268 if ( merchantConfigDictionary . ContainsKey ( "keyAlias" ) )
237269 {
238270 KeyAlias = merchantConfigDictionary [ "keyAlias" ] ;
@@ -254,6 +286,96 @@ private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantC
254286 }
255287 }
256288
289+ if ( Equals ( authTypeInput , Enumerations . AuthenticationType . OAUTH ) )
290+ {
291+ IsOAuthTokenAuthType = true ;
292+ key = "accessToken" ;
293+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
294+ {
295+ AccessToken = merchantConfigDictionary [ key ] ;
296+ }
297+ else
298+ {
299+ throw new KeyNotFoundException ( ) ;
300+ }
301+
302+ key = "refreshToken" ;
303+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
304+ {
305+ RefreshToken = merchantConfigDictionary [ key ] ;
306+ }
307+ else
308+ {
309+ throw new KeyNotFoundException ( ) ;
310+ }
311+ }
312+
313+ if ( Equals ( authTypeInput , Enumerations . AuthenticationType . MUTUAL_AUTH ) )
314+ {
315+ key = "clientId" ;
316+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
317+ {
318+ ClientId = merchantConfigDictionary [ key ] ;
319+ }
320+ else
321+ {
322+ throw new KeyNotFoundException ( ) ;
323+ }
324+
325+ key = "clientSecret" ;
326+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
327+ {
328+ ClientSecret = merchantConfigDictionary [ key ] ;
329+ }
330+ else
331+ {
332+ throw new KeyNotFoundException ( ) ;
333+ }
334+ }
335+
336+ key = "enableClientCert" ;
337+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
338+ {
339+ EnableClientCert = merchantConfigDictionary [ key ] ;
340+ }
341+ else
342+ {
343+ EnableClientCert = "false" ;
344+ }
345+
346+ if ( Equals ( bool . Parse ( EnableClientCert . ToString ( ) ) , true ) )
347+ {
348+ key = "clientCertFile" ;
349+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
350+ {
351+ ClientCertFile = merchantConfigDictionary [ key ] ;
352+ }
353+ else
354+ {
355+ throw new KeyNotFoundException ( ) ;
356+ }
357+
358+ key = "clientCertPassword" ;
359+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
360+ {
361+ ClientCertPassword = merchantConfigDictionary [ key ] ;
362+ }
363+ else
364+ {
365+ throw new KeyNotFoundException ( ) ;
366+ }
367+
368+ key = "clientCertDirectory" ;
369+ if ( merchantConfigDictionary . ContainsKey ( key ) && ! string . IsNullOrEmpty ( merchantConfigDictionary [ key ] ) )
370+ {
371+ ClientCertDirectory = merchantConfigDictionary [ key ] ;
372+ }
373+ else
374+ {
375+ throw new KeyNotFoundException ( ) ;
376+ }
377+ }
378+
257379 if ( merchantConfigDictionary . ContainsKey ( "enableLog" ) )
258380 {
259381 EnableLog = merchantConfigDictionary [ "enableLog" ] ;
@@ -314,12 +436,7 @@ private void SetValuesUsingDictObj(IReadOnlyDictionary<string, string> merchantC
314436
315437 private void ValidateProperties ( )
316438 {
317- // VALIDATIONS COMMON FOR BOTH AUTH MECH.
318- if ( string . IsNullOrEmpty ( MerchantId ) )
319- {
320- throw new Exception ( $ "{ Constants . ErrorPrefix } Merchant Config field - MerchantID is Mandatory") ;
321- }
322-
439+
323440 // Validating and setting up Authentication type
324441 Enumerations . ValidateAuthenticationType ( AuthenticationType ) ;
325442
@@ -369,6 +486,18 @@ private void ValidateProperties()
369486 {
370487 HostName = Constants . IDCProdHostName ;
371488 }
489+ else if ( RunEnvironmentTester . Equals ( Constants . CybsMutualAuthProdRunEnv . ToUpper ( ) ) )
490+ {
491+ HostName = Constants . CybsMutualAuthProdHostName ;
492+ }
493+ else if ( RunEnvironmentTester . Equals ( Constants . CybsMutualAuthSandboxRunEnv . ToUpper ( ) ) )
494+ {
495+ HostName = Constants . CybsMutualAuthSandboxHostName ;
496+ }
497+ else if ( RunEnvironmentTester . Equals ( Constants . SitMutualAuthRunEnv . ToUpper ( ) ) )
498+ {
499+ HostName = Constants . SitMutualAuthHostName ;
500+ }
372501 else
373502 {
374503 HostName = RunEnvironment . ToLower ( ) ;
@@ -378,6 +507,11 @@ private void ValidateProperties()
378507 // 1. FOR HTTP SIGNATURE
379508 if ( IsHttpSignAuthType )
380509 {
510+ if ( string . IsNullOrEmpty ( MerchantId ) )
511+ {
512+ throw new Exception ( $ "{ Constants . ErrorPrefix } Merchant Config field - MerchantID is Mandatory") ;
513+ }
514+
381515 if ( string . IsNullOrEmpty ( MerchantKeyId ) )
382516 {
383517 throw new Exception ( $ "{ Constants . ErrorPrefix } Merchant Config field - MerchantKeyId is Mandatory") ;
@@ -392,6 +526,11 @@ private void ValidateProperties()
392526 // 2. FOR JWT TOKEN
393527 else if ( IsJwtTokenAuthType )
394528 {
529+ if ( string . IsNullOrEmpty ( MerchantId ) )
530+ {
531+ throw new Exception ( $ "{ Constants . ErrorPrefix } Merchant Config field - MerchantID is Mandatory") ;
532+ }
533+
395534 if ( string . IsNullOrEmpty ( KeyAlias ) )
396535 {
397536 KeyAlias = MerchantId ;
0 commit comments