You need to sign in to do that
Don't have an account?
Avinash Kumar 90
Mentioning username / password in code
Hello All,
Do we need to mention username and password in the code ? I got this sample code from salesforce documentation.
Any help would be greatly appreciated. I read that if one is using OAuth then user credentials need not be mentioned in the code.
public boolean loginSample() {
boolean success = false;
String username = "username";
String password = "password";
String authEndPoint = "https://login.salesforce.com/services/Soap/c/24.0/";
try {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(password);
System.out.println("AuthEndPoint: " + authEndPoint);
config.setAuthEndpoint(authEndPoint);
connection = new EnterpriseConnection(config);
// Print user and session info
GetUserInfoResult userInfo = connection.getUserInfo();
System.out.println("UserID: " + userInfo.getUserId());
System.out.println("User Full Name: " + userInfo.getUserFullName());
System.out.println("User Email: " + userInfo.getUserEmail());
System.out.println();
System.out.println("SessionID: " + config.getSessionId());
System.out.println("Auth End Point: " + config.getAuthEndpoint());
System.out
.println("Service End Point: " + config.getServiceEndpoint());
System.out.println();
success = true;
} catch (ConnectionException ce) {
ce.printStackTrace();
}
return success;
}
Regards,
Avinash
Do we need to mention username and password in the code ? I got this sample code from salesforce documentation.
Any help would be greatly appreciated. I read that if one is using OAuth then user credentials need not be mentioned in the code.
public boolean loginSample() {
boolean success = false;
String username = "username";
String password = "password";
String authEndPoint = "https://login.salesforce.com/services/Soap/c/24.0/";
try {
ConnectorConfig config = new ConnectorConfig();
config.setUsername(username);
config.setPassword(password);
System.out.println("AuthEndPoint: " + authEndPoint);
config.setAuthEndpoint(authEndPoint);
connection = new EnterpriseConnection(config);
// Print user and session info
GetUserInfoResult userInfo = connection.getUserInfo();
System.out.println("UserID: " + userInfo.getUserId());
System.out.println("User Full Name: " + userInfo.getUserFullName());
System.out.println("User Email: " + userInfo.getUserEmail());
System.out.println();
System.out.println("SessionID: " + config.getSessionId());
System.out.println("Auth End Point: " + config.getAuthEndpoint());
System.out
.println("Service End Point: " + config.getServiceEndpoint());
System.out.println();
success = true;
} catch (ConnectionException ce) {
ce.printStackTrace();
}
return success;
}
Regards,
Avinash
Please check with below link for better understanding of OAuth protocol.
- https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_guidelines_yourtools.htm?search_text=Oauth
Regards,Nagendra.