@@ -65,7 +65,7 @@ mvn install
6565<dependency >
6666 <groupId >com.api.util</groupId >
6767 <artifactId >ApiSecurity</artifactId >
68- <version >1.2 .0-SNAPSHOT</version >
68+ <version >1.3 .0-SNAPSHOT</version >
6969</dependency >
7070
7171```
@@ -133,20 +133,75 @@ repositories {
133133 mavenLocal()
134134}
135135dependencies {
136- compile group: 'com.api.util', name: 'ApiSecurity', version: '1.0-SNAPSHOT'
136+ compile group: 'com.api.util', name: 'ApiSecurity', version: '1.3. 0-SNAPSHOT'
137137}
138138
139139```
140140
141141### Development
142142
143- #### Constructing Signature BaseString
143+ #### Preparing HTTP Signature Token
144+
145+ Append this signature token into the Authorization header of the HTTP request
146+
147+ Params:
148+ * realm
149+ * authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg'
150+ * httpMethod
151+ * urlPath - Signing URL, remember to append <<tenant >>.e.api.gov.sg or <<tenant >>-pvt.i.api.gov.sg in <<URL >>
152+ * appId - App ID created in Gateway
153+ * secret - set to null for REST L2 SHA256WITHRSA
154+ * formList - to support parameter for form data if any
155+ * password
156+ * alias
157+ * fileName
158+ * nonce - set to null for random generated number
159+ * timestamp - set to null for current timestamp
160+
161+
162+ ``` java
163+ String realm = " <<your_client_host_url>>"
164+ String authPrefix = " <<authPrefix>>
165+ String httpMethod = " get"
166+ //Append the query param in the url or else add as ApiList
167+ String signingUrl = " https: // <<URL>>/api/v1/?param1=first¶m2=123";
168+ String certFileName = " certificates/ssc.alpha.example.com.p12" ;
169+ String password = " <<passphrase>>" ;
170+ String alias = " alpha" ;
171+ String appId = " <<appId>>" ;
172+ String secret = null ;
173+ // only needed for Content-Type: application/x-www-form-urlencoded, else null
174+ ApiList formList = null ;
175+ String nonce = null ;
176+ String timestamp = null ;
177+
178+
179+ // optional for QueryParam - in-case not append the query parameters in the signingUrl
180+ // Sring signingUrl = "https://<<tenant>>-pvt.i.api.gov.sg/api/v1"
181+ ApiList queryParam = new ApiList ();
182+ queryParam. add(" query1" ," value1" );
183+
184+ // optional for formList
185+ ApiList formList = new ApiList ();
186+ formList. add(" param1" , " data1" );
187+
188+ // If queryParam and formList are both available, combine the list before submitting
189+ formList. addAll(queryParam);
190+
191+ try {
192+ String signature = ApiSigning . getSignatureToken(authPrefix, authPrefix, httpMethod, signingUrl, appId, secret, formList, password, alias, certFileName, nonce, timestamp);
193+ } catch (ApiUtilException e) {
194+ e. printStackTrace();
195+ }
196+ ```
197+
198+ #### Constructing Signature BaseString (for reference only)
144199
145200Method:
146201* getBaseString
147202
148203Params:
149- * authPrefix - Authorization Header scheme prefix , i.e 'prefix_appId '
204+ * authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg '
150205* signatureMethod
151206* appId - App ID created in Gateway
152207* urlPath
@@ -156,7 +211,7 @@ Params:
156211* timestamp - set to null for current timestamp
157212
158213``` java
159- String url = " https://<<URL>>/api/v1/?param1=first&ab- param2=123" ;
214+ String signingUrl = " https://<<URL>>/api/v1/?param1=first¶m2=123" ;
160215
161216ApiList formList = new ApiList ();
162217formList. add(" param1" , " data1" );
@@ -168,7 +223,7 @@ baseString = ApiSigning.getBaseString(
168223 " <<authPrefix>>" ,
169224 " HMACSHA256" ,
170225 " <<appId>>" ,
171- url ,
226+ signingUrl ,
172227 " post" ,
173228 formList,
174229 " 6584351262900708156" ,
@@ -183,7 +238,7 @@ System.out.println(baseString);
183238
184239```
185240
186- #### Constructing HMAC256 L1 Header
241+ #### Constructing HMAC256 L1 Header (for reference only)
187242
188243Method:
189244* getHMACSignature
@@ -207,7 +262,7 @@ try {
207262
208263```
209264
210- #### Constructing RSA256 L2 Header
265+ #### Constructing RSA256 L2 Header (for reference only)
211266
212267Method:
213268* getRSASignature
@@ -217,7 +272,7 @@ Params:
217272* privateKey
218273
219274``` java
220- String baseString = " GET&https://<<URL>/api/v1/&ap=裕廊坊 心邻坊&<<authPrefix>>_app_id=<<appId>>&<<authPrefix>>_nonce=7231415196459608363&<<authPrefix>>_signature_method=SHA256withRSA&<<authPrefix>>_timestamp=1502164219425&<<authPrefix>>_version=1.0&oq=c# nunit mac &q=c# nunit mac " ;
275+ String baseString = " GET&https://<<URL>/api/v1/&ap=裕廊坊 心邻坊&<<authPrefix>>_app_id=<<appId>>&<<authPrefix>>_nonce=7231415196459608363&<<authPrefix>>_signature_method=SHA256withRSA&<<authPrefix>>_timestamp=1502164219425&<<authPrefix>>_version=1.0&oq=123 &q=abc " ;
221276String alias = " alpha" ;
222277String password = " <<passphrase>>" ;
223278String keyStoreFileName = " certificates/ssc.alpha.example.com.p12" ;
@@ -240,43 +295,6 @@ try {
240295
241296```
242297
243- #### Preparing HTTP Signature Token
244-
245- Append this signature token into the Authorization header of the HTTP request
246-
247- Params:
248- * realm
249- * authPrefix - Authorization Header scheme prefix , i.e 'prefix_appId'
250- * httpMethod
251- * urlPath
252- * appId - App ID created in Gateway
253- * secret - set to null for REST L2 SHA256WITHRSA
254- * formList
255- * password
256- * alias
257- * fileName
258- * nonce - set to null for random generated number
259- * timestamp - set to null for current timestamp
260-
261-
262- ``` java
263- String url = " https://<<URL>>/api/v1/?ap=裕廊坊%20心邻坊" ;
264- String certFileName = " certificates/ssc.alpha.example.com.p12" ;
265- String password = " <<passphrase>>" ;
266- String alias = " alpha" ;
267- String appId = " <<appId>>" ;
268- String secret = null ;
269- ApiList formList = null ;
270- String nonce = null ;
271- String timestamp = null ;
272-
273- try {
274- String signature = ApiSigning . getSignatureToken(" http://api.test.io/l2" , " <<authPrefix>>" , " get" , url, appId, null , null , password, alias, certFileName, nonce, timestamp);
275- } catch (ApiUtilException e) {
276- e. printStackTrace();
277- }
278- ```
279-
280298## Contributing
281299For more information about contributing PRs and issues, see [ CONTRIBUTING.md] ( .github/CONTRIBUTING.md ) .
282300
0 commit comments