
Below is my java code :
String tokens = OAuthConnection.getUpdatedAccessToken( "https://login.salesforce.com/services/oauth2/token?", getOathToken("refresh_token",organization_id), propertiesDao.getConsumerOathKey(), propertiesDao.getSecret());
public static String[] getUpdatedAccessToken(String loginurl, String refresh_token,String customerKey, String secret){
String[] arr = new String[2];
String params = "grant_type=refresh_token&client_id="+customerKey+"&client_secret="+secret+"&refresh_token="+refresh_token;
try {
HttpUtility.sendGetRequest(loginurl+""+params);
String[] respons = HttpUtility.readMultipleLinesRespone();
JSONArray array;
StringBuilder temp = new StringBuilder();
for (String element : respons)
{
temp.append(element);
}
String singleLineResponse = temp.toString();
try {
array = new JSONArray("["+singleLineResponse+"]");
arr[0] = array.getJSONObject(0).getString("access_token");
arr[1] = array.getJSONObject(0).getString("id");
} catch (JSONException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
finally{
HttpUtility.disconnect();
}
return arr;
}
I use this token to create salesforce connection further.
This gives error :INVALID_LOGIN : Invalid username, password, security token; or user locked out.So, I tried below code to use TLS1.2 before calling url :
System.setProperty("https.protocols", "TLSv1.2");
This works sometimes, but is inconsistent. Still gives same error.
Please let me know how can I fix this issue.
Hi Jeff,The security token is needed if you are trying to connect from a IP range out of the IP ranges whitelist of salesforce.Ensure that the profile associated to your user has whitelisted the ip range you are connecting from.More info here:https://help.salesforce.com/articleView?id=user_security_token.htm&type=0Thanks,Nagendra.