Skip to content

Commit

Permalink
Merge pull request #5 from GovTechSG/development
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
Kelvin Wijaya authored Nov 20, 2018
2 parents 529269d + 509a483 commit c969007
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
```
public static void L1Sample()
Expand Down Expand Up @@ -180,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
Expand Down

0 comments on commit c969007

Please sign in to comment.