Skip to content

Commit 509a483

Browse files
author
Kelvin Wijaya
authored
Update README.md
1 parent 94ba970 commit 509a483

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The ApiUtilLib Library provide the utility class ApiList to construct request Qu
7272
**NOTE**
7373

7474
For **formData** parameter used for Signature generation, the key value parameters **do not** need to be URL encoded,
75-
When your client program is making the actual HTTP POST call, the key value parameters **has** to be URL encoded
75+
When you use this client library method **ApiAuthorization.HttpRequest**, it will do the url-encoding during the HTTP call
7676

7777
### How to Generate HMAC256 L1 Authorization Header
7878
```
@@ -185,6 +185,53 @@ static string GetLocalPath(string relativeFileName)
185185
186186
return localPath;
187187
}
188+
```
189+
#### Sample HTTP POST Call for x-www-form-urlencoded with APEX L1 Security (for reference only)
190+
191+
```
192+
[Test]
193+
public static void Http_Call_Test()
194+
{
195+
// application realm
196+
string realm = "http://example.api.test/token";
197+
198+
// authorization prefix
199+
string authPrefix = "Apex_l1_eg";
200+
201+
// app id and app secret assign to the application
202+
string appId = "tenant-1X2w7NQPzjO2azDu904XI5AE";
203+
string appSecret = "s0m3s3cr3t";
204+
var formData = new ApiUtilLib.ApiList();
205+
206+
formData.Add("key1", "value1);
207+
formData.Add("key2", "value2");
208+
209+
// api signing gateway name and path
210+
string gatewayName = "https://tenant.e.api.gov.sg";
211+
string apiPath = "api14021live/resource";
212+
string baseUrl = string.Format("{0}/{1}", gatewayName, apiPath);
213+
Console.WriteLine("\n>>>baseUrl :: '{0}'<<<", baseUrl);
214+
Console.WriteLine("\n>>>appId :: '{0}'<<<", appId);
215+
Console.WriteLine("\n>>>appSecret :: '{0}'<<<", appSecret);
216+
// authorization header
217+
var authorizationHeader = ApiAuthorization.Token(realm, authPrefix, HttpMethod.POST, new Uri(baseUrl), appId, appSecret, formData);
218+
219+
Console.WriteLine("\n>>>Authorization Header :: '{0}'<<<", authorizationHeader);
220+
221+
// if the target gateway name is different from signing gateway name
222+
string targetBaseUrl = "https://tenant.api.gov.sg/api14021live/resource";
223+
224+
225+
// this method only for verification only
226+
// expecting result to be 200
227+
228+
var result = ApiAuthorization.HttpRequest(new Uri(targetBaseUrl), authorizationHeader, formData, HttpMethod.POST, ignoreServerCert: true);
229+
Console.WriteLine(result);
230+
Console.ReadLine();
231+
232+
Assert.True(true);
233+
}
234+
188235
```
189236

190237
## Release

0 commit comments

Comments
 (0)