use of org.talend.salesforce.oauth.Token in project tdi-studio-se by Talend.
the class SforceOAuthConnection method renewSession.
@Override
protected void renewSession() throws Exception {
Token token = loginWithOAuth();
String session_id = token.getAccess_token();
String endpoint = OAuthClient.getSOAPEndpoint(token, apiVersion);
this.serviceEndPoint = endpoint;
SforceManagementUtil.setEndpoint(stub, endpoint);
sh.setSessionId(session_id);
}
use of org.talend.salesforce.oauth.Token in project tdi-studio-se by Talend.
the class SforceOAuthBulkConnection method loginWithOAuth.
private Token loginWithOAuth() throws Exception {
String session_id = null;
OAuthClient oauthClient = new OAuthClient();
oauthClient.setBaseOAuthURL(login_endpoint);
oauthClient.setClientID(oauth_clientID);
oauthClient.setClientSecret(oauth_clientSecret);
Token token = null;
String refreshToken = null;
// 1. if tokenFile exist, try refresh token
if (tokenFilePath != null) {
Properties prop = new Properties();
FileInputStream inputStream = new FileInputStream(tokenFilePath);
prop.load(inputStream);
inputStream.close();
String storedRefreshToken = (String) prop.get(REFRESHTOKEN_KEY);
if (storedRefreshToken != null) {
token = oauthClient.refreshToken(storedRefreshToken);
session_id = token.getAccess_token();
refreshToken = token.getRefresh_token();
}
}
// 2. try to auth if session_id can't be retrieved
if (session_id == null) {
oauthClient.setCallbackHost(callbackHost);
oauthClient.setCallbackPort(callbackPort);
token = oauthClient.getToken();
refreshToken = token.getRefresh_token();
}
// 3.if refresh token & tokenFile exist, store
if (refreshToken != null && tokenFilePath != null) {
Properties prop = new Properties();
prop.setProperty(REFRESHTOKEN_KEY, refreshToken);
FileOutputStream outputStream = new FileOutputStream(tokenFilePath);
prop.store(outputStream, null);
if (outputStream != null) {
outputStream.close();
}
}
return token;
}
use of org.talend.salesforce.oauth.Token in project tdi-studio-se by Talend.
the class SforceOAuthBulkConnection method renewSession.
@Override
protected void renewSession() throws ConnectionException {
Token token;
try {
token = loginWithOAuth();
} catch (Exception e) {
throw new ConnectionException(e.getMessage());
}
String session_id = token.getAccess_token();
String endpoint = OAuthClient.getBulkEndpoint(token, apiVersion);
config.setSessionId(session_id);
config.setRestEndpoint(endpoint);
}
use of org.talend.salesforce.oauth.Token in project tdi-studio-se by Talend.
the class SforceOAuthConnection method loginWithOAuth.
private Token loginWithOAuth() throws Exception {
String session_id = null;
OAuthClient oauthClient = new OAuthClient();
oauthClient.setBaseOAuthURL(login_endpoint);
oauthClient.setClientID(oauth_clientID);
oauthClient.setClientSecret(oauth_clientSecret);
Token token = null;
String refreshToken = null;
// 1. if tokenFile exist, try refresh token
if (tokenFilePath != null) {
Properties prop = new Properties();
FileInputStream inputStream = new FileInputStream(tokenFilePath);
prop.load(inputStream);
inputStream.close();
String storedRefreshToken = (String) prop.get(REFRESHTOKEN_KEY);
if (storedRefreshToken != null) {
token = oauthClient.refreshToken(storedRefreshToken);
session_id = token.getAccess_token();
refreshToken = token.getRefresh_token();
}
}
// 2. try to auth if session_id can't be retrieved
if (session_id == null) {
oauthClient.setCallbackHost(callbackHost);
oauthClient.setCallbackPort(callbackPort);
token = oauthClient.getToken();
refreshToken = token.getRefresh_token();
}
// 3.if refresh token & tokenFile exist, store
if (refreshToken != null && tokenFilePath != null) {
Properties prop = new Properties();
prop.setProperty(REFRESHTOKEN_KEY, refreshToken);
FileOutputStream outputStream = new FileOutputStream(tokenFilePath);
prop.store(outputStream, null);
if (outputStream != null) {
outputStream.close();
}
}
return token;
}
Aggregations