Skip to content

Commit

Permalink
Revert "updated HMAC Auth logic for api with request params, added ex…
Browse files Browse the repository at this point in the history
…ample class for user apis"

This reverts commit 04557ab
  • Loading branch information
javidlulu committed Oct 12, 2020
1 parent 04557ab commit 74e28d1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 61 deletions.
13 changes: 2 additions & 11 deletions src/main/java/jp/ne/paypay/auth/HmacAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,10 @@ private byte[] getHmacData(String nonce, long epoch, String hash){
localContentType = this.contentType;
}
String DELIMITER = "\n";
return (formatRequestUrl(this.requestUrl) + DELIMITER + this.httpMethod + DELIMITER + nonce + DELIMITER + epoch + DELIMITER
return (this.requestUrl + DELIMITER + this.httpMethod + DELIMITER + nonce + DELIMITER + epoch + DELIMITER
+ localContentType + DELIMITER + hash)
.getBytes(StandardCharsets.UTF_8);
}
private String formatRequestUrl(String requestUrl){
try{
if(requestUrl.contains("?")){
requestUrl = requestUrl.substring(0, requestUrl.indexOf("?"));
}
}catch (Exception e){
System.out.println("Exception while formatting request url for HMAC Auth");
}
return requestUrl;
}
@Override
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
if (apiKey == null || apiSecretKey == null) {
Expand All @@ -94,6 +84,7 @@ public void applyToParams(List<Pair> queryParams, Map<String, String> headerPara
}catch (Exception e){
System.err.println("Error in getting Authorization: "+e);
}

}

public String getApiKey() {
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/jp/ne/paypay/example/UserApiExample.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/test/java/jp/ne/paypay/api/HmacAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public void hmacAuthTest(){
Assert.assertNotNull(hmacAuth.getHttpMethod());
Assert.assertNotNull(hmacAuth.getRequestBody());
Assert.assertNotNull(hmacAuth.getRequestUrl());
hmacAuth.setRequestUrl("/v2/api/test?param=p1");
hmacAuth.applyToParams(queryParams, headerParams);
Assert.assertTrue(headerParams.get("Authorization").startsWith("hmac"));
hmacAuth.setContentType(null);
headerParams = new HashMap<>();
hmacAuth.applyToParams(queryParams, headerParams);
Assert.assertNull(headerParams.get("Authorization"));

}
}

0 comments on commit 74e28d1

Please sign in to comment.