def refresh_token(sf_basic_config): settings = sf_basic_config.get_setting() sublconsole = SublConsole(sf_basic_config) sublconsole.debug('>>>>start to refresh token') from SalesforceXyTools.libs import auth if not settings["use_oauth2"]: return False project_setting = settings is_sandbox = project_setting["is_sandbox"] if "refresh_token" not in project_setting: sublconsole.debug("refresh token missing") return False sublconsole.debug('>>>>load server info') server_info = sublime.load_settings("sfdc.server.sublime-settings") client_id = server_info.get("client_id") client_secret = server_info.get("client_secret") redirect_uri = server_info.get("redirect_uri") oauth = auth.SalesforceOAuth2(client_id, client_secret, redirect_uri, is_sandbox) _refresh_token = project_setting["refresh_token"] # sublconsole.debug(refresh_token) response_json = oauth.refresh_token(_refresh_token) # sublconsole.debug(response_json) if "error" in response_json: sublconsole.debug('>>>>response josn error') sublconsole.debug(response_json) return False if "refresh_token" not in response_json: response_json["refresh_token"] = _refresh_token sublconsole.debug('>>>>refresh_token:') sublconsole.debug(refresh_token) sublconsole.debug('>>>>save session') sf_basic_config.save_session(response_json) sublconsole.debug("------->refresh_token ok!") return True
def sf_oauth2(sf_basic_config): sublconsole = SublConsole(sf_basic_config) settings = sf_basic_config.get_setting() from SalesforceXyTools.libs import auth project_setting = settings # project_setting = settings["default_project_value"] is_sandbox = project_setting["is_sandbox"] if refresh_token(sf_basic_config): return server_info = sublime.load_settings("sfdc.server.sublime-settings") client_id = server_info.get("client_id") client_secret = server_info.get("client_secret") redirect_uri = server_info.get("redirect_uri") oauth = auth.SalesforceOAuth2(client_id, client_secret, redirect_uri, is_sandbox) authorize_url = oauth.authorize_url() sublconsole.debug('authorize_url-->') sublconsole.debug(authorize_url) start_server() open_in_default_browser(sf_basic_config, authorize_url)