amk.sdk.deeplink.presenter.AuthenticationPresenter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java Show documentation
Show all versions of java Show documentation
The AMK Deeplink SDK is a library for AMK's merchant that allow them to be able generate deeplink for their user to pay via AMK Bank app.
package amk.sdk.deeplink.presenter;
import amk.sdk.deeplink.entity.response.OAuthTokenResponse;
import amk.sdk.deeplink.utils.StringUtils;
import com.google.gson.Gson;
import okhttp3.*;
import static amk.sdk.deeplink.entity.model.ApiConstant.*;
class AuthenticationPresenter {
static String getAccessToken(String clientId, String privateKeyPath, String jwtAudience) throws Exception {
String jwtToken = JwtTokenConfigPresenter.generateJwtToken(clientId, privateKeyPath, jwtAudience);
String endpoint = "/api/v1/common/oauth/token";
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "grant_type=" + GRANT_TYPE + "&assertion=" + jwtToken);
Request request = new Request.Builder()
.url(BASE_URL + endpoint)
.method("POST", body)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
Gson gson = new Gson();
OAuthTokenResponse oAuthTokenResponse;
ResponseBody responseBody = response.body();
if (response.isSuccessful() && responseBody != null) {
String json = responseBody.string();
oAuthTokenResponse = gson.fromJson(
json,
OAuthTokenResponse.class
);
if (StringUtils.isBlank(oAuthTokenResponse.getAccess_token())) {
return null;
} else {
return oAuthTokenResponse.getAccess_token();
}
}
return null;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy