Skip to content

Commit

Permalink
Add Pinning certificates + fix instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza Amuzadeh committed Jul 2, 2019
1 parent c68fcad commit 94056dc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
65 changes: 61 additions & 4 deletions app/src/main/java/com/github/restclient/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

initRestClient();
initRestClientWithCP();

findViewById(R.id.buttonSimpleCall).setOnClickListener(view -> {
callSimpleApi();
Expand All @@ -41,24 +41,58 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void initRestClient() {

ArrayMap<String, String> header = new ArrayMap<>();

String clientId = "c3bdf6c5-508f-48ae-9af4-243a24072e31";

String clientSecret = "LnDbEo3yDDcswKMC3h4H";

String site = "https://sandbox.vaslapp.com";

String userName = "android-XoaM8ODAYVcKnB16ob8N";

String passWord = "DOI0qOIa0KT6ViYmS1k6";

header.put("Content-Type", "application/x-www-form-urlencoded");

restClient = new RestClient
.Builder(this)
.setAuthorizationBasic(userName, passWord)
.setAuthorizationOauth2(site + "/oauth/token", clientId, clientSecret)
.setDebugEnable(true)
.setHeader(header)
.setConnectionTimeOut(15000)
.build();
}

private void initRestClientWithCP() {

ArrayMap<String, String> header = new ArrayMap<>();

String clientId = "c3bdf6c5-508f-48ae-9af4-243a24072e31";

String clientSecret = "LnDbEo3yDDcswKMC3h4H";

String site = "http://sandbox.vaslapp.com";
String site = "https://sandbox.vaslapp.com";

String userName = "android-XoaM8ODAYVcKnB16ob8N";

String passWord = "DOI0qOIa0KT6ViYmS1k6";

header.put("Content-Type", "application/x-www-form-urlencoded");

restClient = new RestClient.Builder(this)
.setAuthorizationOauth2("https://accounts.spotify.com/api/token", clientId, clientSecret)
ArrayMap<String, String> CPKArray = new ArrayMap<>();
CPKArray.put("sandbox.vaslapp.com", "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=");

restClient = new RestClient
.Builder(this)
.setAuthorizationBasic(userName, passWord)
.setAuthorizationOauth2(site + "/oauth/token", clientId, clientSecret)
.setDebugEnable(true)
.setHeader(header)
.setCPKArray(CPKArray)
.setConnectionTimeOut(15000)
.build();
}

Expand Down Expand Up @@ -90,6 +124,29 @@ public void onFailure(int errorCode, String errorMsg) {
}

private void callCPApi() {
RequestParams params = new RequestParams(RequestBodyType.FormData);
restClient.GET("https://sandbox.vaslapp.com/cache",
"",
new ResponseJsonHandler() {
@Override
protected void onSuccess(JSONObject result) {
Log.d(TAG, "response " + result);
}

@Override
protected void onSuccess(JSONArray result) {
Log.d(TAG, "response " + result);
}

@Override
protected void onSuccess(String result) {
Log.d(TAG, "response " + result);
}

@Override
public void onFailure(int errorCode, String errorMsg) {
Log.d(TAG, "onFailure " + errorMsg);
}
});
}
}
2 changes: 1 addition & 1 deletion library/src/main/java/com/github/library/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static synchronized OkHttpClient getClient(int timeOut, boolean enableDebug) {
.connectTimeout(timeOut, TimeUnit.MILLISECONDS);

if (enableDebug)
instanceBuilder = instance.newBuilder().addInterceptor(new LoggingInterceptor());
instanceBuilder.addInterceptor(new LoggingInterceptor());

if (certificatePinner != null)
instanceBuilder.certificatePinner(certificatePinner);
Expand Down

0 comments on commit 94056dc

Please sign in to comment.