From 94ba970f4d7da1a418c38a2c17c2b0f2070bae7a Mon Sep 17 00:00:00 2001 From: Kelvin Wijaya Date: Fri, 16 Nov 2018 11:14:21 +0800 Subject: [PATCH 1/2] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d636aed..bcae287 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,11 @@ The ApiUtilLib Library provide the utility class ApiList to construct request Qu // phoneNo=%2B1+1234+4567+890&street=Hellowood+Street&state=AP ``` +**NOTE** + +For **formData** parameter used for Signature generation, the key value parameters **do not** need to be URL encoded, +When your client program is making the actual HTTP POST call, the key value parameters **has** to be URL encoded + ### How to Generate HMAC256 L1 Authorization Header ``` public static void L1Sample() From 509a483efe0aadd48cb2f0eee6f7fd69bb2d3194 Mon Sep 17 00:00:00 2001 From: Kelvin Wijaya Date: Fri, 16 Nov 2018 17:10:45 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bcae287..063dab4 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ The ApiUtilLib Library provide the utility class ApiList to construct request Qu **NOTE** For **formData** parameter used for Signature generation, the key value parameters **do not** need to be URL encoded, -When your client program is making the actual HTTP POST call, the key value parameters **has** to be URL encoded +When you use this client library method **ApiAuthorization.HttpRequest**, it will do the url-encoding during the HTTP call ### How to Generate HMAC256 L1 Authorization Header ``` @@ -185,6 +185,53 @@ static string GetLocalPath(string relativeFileName) return localPath; } +``` +#### Sample HTTP POST Call for x-www-form-urlencoded with APEX L1 Security (for reference only) + +``` +[Test] +public static void Http_Call_Test() +{ + // application realm + string realm = "http://example.api.test/token"; + + // authorization prefix + string authPrefix = "Apex_l1_eg"; + + // app id and app secret assign to the application + string appId = "tenant-1X2w7NQPzjO2azDu904XI5AE"; + string appSecret = "s0m3s3cr3t"; + var formData = new ApiUtilLib.ApiList(); + + formData.Add("key1", "value1); + formData.Add("key2", "value2"); + + // api signing gateway name and path + string gatewayName = "https://tenant.e.api.gov.sg"; + string apiPath = "api14021live/resource"; + string baseUrl = string.Format("{0}/{1}", gatewayName, apiPath); + Console.WriteLine("\n>>>baseUrl :: '{0}'<<<", baseUrl); + Console.WriteLine("\n>>>appId :: '{0}'<<<", appId); + Console.WriteLine("\n>>>appSecret :: '{0}'<<<", appSecret); + // authorization header + var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.POST, new Uri(baseUrl), appId, appSecret, formData); + + Console.WriteLine("\n>>>Authorization Header :: '{0}'<<<", authorizationHeader); + + // if the target gateway name is different from signing gateway name + string targetBaseUrl = "https://tenant.api.gov.sg/api14021live/resource"; + + + // this method only for verification only + // expecting result to be 200 + + var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader, formData, HttpMethod.POST, ignoreServerCert: true); + Console.WriteLine(result); + Console.ReadLine(); + + Assert.True(true); +} + ``` ## Release