Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ed8867f
renamed MleKeyAlias to RequestMleKeyAlias
aastgoel Sep 3, 2025
d0ffbf4
Added Response MLE Params in the Merchant Config
aastgoel Sep 10, 2025
7e88865
updated Constructor and set the Merchant Config Params
aastgoel Sep 10, 2025
b84c08e
Added Validation for Response MLE Params
aastgoel Sep 10, 2025
39db3fb
added new constructor and convert function for mapToControlMLEonAPI
aastgoel Sep 11, 2025
9296776
modified setter for mapToControlMLEonAPI and added validation for Map…
aastgoel Sep 11, 2025
8b7321e
modified MLE Validation to work with new split maps and changed the m…
aastgoel Sep 11, 2025
a35a638
added Validation for resonseMleKID config
aastgoel Sep 11, 2025
9dc1b91
added CheckIsResponseMLEForAPI function in MLEUtility
aastgoel Sep 11, 2025
50f0ee1
dropping support for <string,bool> mapToControlMLEonAPI
aastgoel Sep 12, 2025
3fb548d
added doc for RequestMleKeyAlias
aastgoel Sep 17, 2025
5dff2f4
added v-c-response-mle-kid in jwt body if response MLE for API is ena…
aastgoel Sep 17, 2025
71f717d
renamed GetMLECertificate to GetRequestMLECertificate
aastgoel Sep 17, 2025
06136a9
Added validation for responseMlePrivateKey and responseMlePrivateKeyF…
aastgoel Sep 17, 2025
4cb207b
Added function to read private key from files like pem, p12 , p8 etc
aastgoel Sep 18, 2025
9b4505b
new label added for response mle key
aastgoel Sep 18, 2025
9006dc7
added Caching support for Response MLE Private Key
aastgoel Sep 21, 2025
08dce7f
added CheckIsMleEncryptedResponse and DecryptMleResponsePayload in ML…
aastgoel Sep 21, 2025
da3f3d4
changed error messages for private key handling from files
aastgoel Sep 23, 2025
f068c07
fixed log message
aastgoel Sep 23, 2025
57de176
changed the mustache files for API , added isResponseMLEForApi flag a…
aastgoel Sep 23, 2025
cc85fec
changed ApiClient functions to make use of isResponseMLEForAPi flag. …
aastgoel Sep 23, 2025
030cb00
added new param ResponseMlePrivateKey, changed mapToControlMLEonAPI d…
aastgoel Sep 23, 2025
503da26
minor fix
aastgoel Sep 23, 2025
040a2f0
PKCS1 encrypted keys are supported, removed exception
aastgoel Sep 23, 2025
4177403
updated error handling for wrong PrivateKey use
aastgoel Sep 23, 2025
a75d3b0
Merge remote-tracking branch 'origin/restclient-rewrite' into feature…
aastgoel Sep 24, 2025
9f2e255
Added responseMlePrivateKey parameter to MerchantConfig initialization
aastgoel Sep 24, 2025
ecc2786
Merge remote-tracking branch 'origin/restclient-rewrite' into feature…
aastgoel Sep 24, 2025
0ce5409
removed isResponseMLEForApi from JwtToken file, handled it in JwtToke…
aastgoel Sep 25, 2025
1d39df5
replaced string with SecureString for password field
aastgoel Sep 25, 2025
0c10f62
changed OAuthApi deserialize function call
aastgoel Sep 26, 2025
6aa53b2
minor fix
aastgoel Sep 26, 2025
7cd956b
review comment changes
aastgoel Sep 26, 2025
56776ea
review comment changes
aastgoel Sep 30, 2025
5eae8b1
moved Utility Functions to PEMUtility
aastgoel Sep 30, 2025
a8193cf
Merge branch 'feature/mle-for-response-2' into feature/mle-for-respon…
aastgoel Oct 6, 2025
19a30eb
Merge pull request #130 from CyberSource/feature/mle-for-response-2
gaubansa Oct 6, 2025
524dbf5
proper error handling
aastgoel Oct 6, 2025
d43a5fd
Merge pull request #131 from CyberSource/feature/mle-for-response-3
aastgoel Oct 8, 2025
4dff61c
Merge remote-tracking branch 'origin/future' into feature/mle-for-res…
aastgoel Oct 8, 2025
40165ed
fixed checkmarx findings
aastgoel Oct 8, 2025
e9ea9ad
made code same as dotnet
aastgoel Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
using System.Security.Cryptography.X509Certificates;
using System.Text;
using AuthenticationSdk.core;
using Newtonsoft.Json.Linq;

namespace AuthenticationSdk.authentication.jwt
{
public class JwtTokenGenerator : ITokenGenerator
{
private readonly MerchantConfig _merchantConfig;
private readonly JwtToken _jwtToken;
private readonly bool _isResponseMLEForApi;

public JwtTokenGenerator(MerchantConfig merchantConfig)
public JwtTokenGenerator(MerchantConfig merchantConfig, bool isResponseMLEForApi)
{
_isResponseMLEForApi = isResponseMLEForApi;
_merchantConfig = merchantConfig;
_jwtToken = new JwtToken(_merchantConfig);
}
Expand Down Expand Up @@ -54,7 +57,16 @@ private string SetToken()

private string TokenForCategory1()
{
var jwtBody = $"{{ \"iat\":\"{DateTime.Now.ToUniversalTime().ToString("r")}\"}}";
JObject claimSetJson = new JObject();
claimSetJson["iat"] = DateTime.Now.ToUniversalTime().ToString("r");

if (_isResponseMLEForApi)
{
claimSetJson["v-c-response-mle-kid"] = _merchantConfig.ResponseMleKID;
}

String jwtBody = "";
jwtBody = claimSetJson.ToString(Newtonsoft.Json.Formatting.None);

var x5Cert = _jwtToken.Certificate;

Expand Down Expand Up @@ -82,7 +94,18 @@ private string TokenForCategory2()
{
var digest = GenerateDigest(_jwtToken.RequestJsonData);

var jwtBody = $"{{\n \"digest\":\"{digest}\", \"digestAlgorithm\":\"SHA-256\", \"iat\":\"{DateTime.Now.ToUniversalTime().ToString("r")}\"}}";
JObject claimSetJson = new JObject();
claimSetJson["digest"] = digest;
claimSetJson["digestAlgorithm"] = "SHA-256";
claimSetJson["iat"] = DateTime.Now.ToUniversalTime().ToString("r");

if (_isResponseMLEForApi)
{
claimSetJson["v-c-response-mle-kid"] = _merchantConfig.ResponseMleKID;
}

String jwtBody = "";
jwtBody = claimSetJson.ToString(Newtonsoft.Json.Formatting.None);

var x5Cert = _jwtToken.Certificate;

Expand All @@ -101,7 +124,6 @@ private string TokenForCategory2()
};

var token = Jose.JWT.Encode(jwtBody, privateKey, Jose.JwsAlgorithm.RS256, cybsHeaders);

return token;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public HttpToken GetSignature()
* @return a JwtToken object (JWT Bearer Token),
* based on the Merchant Configuration passed to the Constructor of Authorize Class
*/
public JwtToken GetToken()
public JwtToken GetToken(bool isResponseMLEForApi = false)
{
try
{
Expand All @@ -101,7 +101,7 @@ public JwtToken GetToken()
throw new Exception("Missing or Empty Credentials : MerchantID or KeyAlias or KeyPassphrase");
}

var tokenObj = (JwtToken)new JwtTokenGenerator(_merchantConfig).GetToken();
var tokenObj = (JwtToken)new JwtTokenGenerator(_merchantConfig, isResponseMLEForApi).GetToken();

if (_merchantConfig.IsGetRequest || _merchantConfig.IsDeleteRequest)
{
Expand Down
Loading