@@ -65,7 +65,7 @@ mvn install
65
65
<dependency >
66
66
<groupId >com.api.util</groupId >
67
67
<artifactId >ApiSecurity</artifactId >
68
- <version >1.2 .0-SNAPSHOT</version >
68
+ <version >1.3 .0-SNAPSHOT</version >
69
69
</dependency >
70
70
71
71
```
@@ -133,20 +133,75 @@ repositories {
133
133
mavenLocal()
134
134
}
135
135
dependencies {
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'
137
137
}
138
138
139
139
```
140
140
141
141
### Development
142
142
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)
144
199
145
200
Method:
146
201
* getBaseString
147
202
148
203
Params:
149
- * authPrefix - Authorization Header scheme prefix , i.e 'prefix_appId '
204
+ * authPrefix - Authorization Header scheme prefix , i.e 'Apex_l2_eg '
150
205
* signatureMethod
151
206
* appId - App ID created in Gateway
152
207
* urlPath
@@ -156,7 +211,7 @@ Params:
156
211
* timestamp - set to null for current timestamp
157
212
158
213
``` java
159
- String url = " https://<<URL>>/api/v1/?param1=first&ab- param2=123" ;
214
+ String signingUrl = " https://<<URL>>/api/v1/?param1=first¶m2=123" ;
160
215
161
216
ApiList formList = new ApiList ();
162
217
formList. add(" param1" , " data1" );
@@ -168,7 +223,7 @@ baseString = ApiSigning.getBaseString(
168
223
" <<authPrefix>>" ,
169
224
" HMACSHA256" ,
170
225
" <<appId>>" ,
171
- url ,
226
+ signingUrl ,
172
227
" post" ,
173
228
formList,
174
229
" 6584351262900708156" ,
@@ -183,7 +238,7 @@ System.out.println(baseString);
183
238
184
239
```
185
240
186
- #### Constructing HMAC256 L1 Header
241
+ #### Constructing HMAC256 L1 Header (for reference only)
187
242
188
243
Method:
189
244
* getHMACSignature
@@ -207,7 +262,7 @@ try {
207
262
208
263
```
209
264
210
- #### Constructing RSA256 L2 Header
265
+ #### Constructing RSA256 L2 Header (for reference only)
211
266
212
267
Method:
213
268
* getRSASignature
@@ -217,7 +272,7 @@ Params:
217
272
* privateKey
218
273
219
274
``` 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 " ;
221
276
String alias = " alpha" ;
222
277
String password = " <<passphrase>>" ;
223
278
String keyStoreFileName = " certificates/ssc.alpha.example.com.p12" ;
@@ -240,43 +295,6 @@ try {
240
295
241
296
```
242
297
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
-
280
298
## Contributing
281
299
For more information about contributing PRs and issues, see [ CONTRIBUTING.md] ( .github/CONTRIBUTING.md ) .
282
300
0 commit comments