Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug withSaasusSigV1 #2

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/main/java/saasus/sdk/modules/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import okhttp3.Call;
import okhttp3.RequestBody;
import okio.Buffer;

public class Utils {

Expand Down Expand Up @@ -36,10 +40,18 @@ public static String withSaasusSigV1(Call call) throws Exception {

String fullResourceUri = (queryString == null)
? host + applyResource
: host + applyResource + "?" + queryString;
String body = (call.request().body() == null)
? ""
: call.request().body().toString();
: host + applyResource + "?" + queryString;
String body = "";
// ApiClientに同様のメソッド#requestBodyToStringはあるがprivateのためrewrite
if (call.request().body() != null) {
try {
final Buffer buffer = new Buffer();
call.request().body().writeTo(buffer);
body = buffer.readUtf8();
} catch (final IOException e) {
throw new Exception(e);
}
}

String message = now.concat(apiKey).concat(method).concat(fullResourceUri).concat(body);
byte[] hash = signatureHmac.doFinal(message.getBytes(StandardCharsets.UTF_8));
Expand Down