Module: Authenticate
- Included in:
- Salesforce::Rest::AsfRest
- Defined in:
- lib/Salesforce/rest/asf_rest_authenticate.rb
Class Method Summary collapse
-
.included(base) ⇒ Object
class methods.
Class Method Details
.included(base) ⇒ Object
class methods
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/Salesforce/rest/asf_rest_authenticate.rb', line 22 def self.included(base) class << base # Initializes the adapter, using username, password. A good place to invoke # it includes 'setup()' method in the 'test_helper' and Rails init files. # usage -> bootup_rest_adapter(username, password, api_version) def bootup_rest_adapter(username, password, api_version) p "*" * 80 p 'Set up code' login_svr = 'https://login.salesforce.com' api_version = api_version ? api_version : '21.0' uri = URI.parse(login_svr) uri.path = "/services/Soap/u/" + (api_version).to_s url = uri.to_s binding = RForce::Binding.new(url, nil, nil) soap_response = binding.login(username, password) soap_server_url = soap_response.loginResponse.result.serverUrl security_token = soap_response.loginResponse.result.sessionId user_id = soap_response.loginResponse.result.userId puts "binding user id is: " + user_id rest_svr = soap_server_url.gsub(/-api\S*/mi, "") + ".salesforce.com" rest_version = "v" + api_version self.setup(security_token, rest_svr, rest_version) puts "oauth token is: " + security_token puts 'rest_svr: ' + rest_svr return [security_token, rest_svr, rest_version] end # Ignite the adapter, using the config_file, This will in term invoke # bootup_rest_adapter(username, password, api_version) or set up with # consumer key/secret with omniauth def ignite_adapter(config_file) #Read the configuration file begin asf_rest_config = YAML::load(File.open(config_file)) auth_scheme = asf_rest_config["asf-rest-config"] ["auth_scheme"] puts "ASF-REST-Adapter setting:" puts "Auth name:" + auth_scheme #setup the default adapter with relevant auth schema (username/password) or (Omniauth) case auth_scheme when "username_password" then puts 'Setting up adapter using username/password' username = asf_rest_config["asf-rest-config"]["username"] password = asf_rest_config["asf-rest-config"]["password"] login_svr = asf_rest_config["asf-rest-config"]["url"].to_s api_version = asf_rest_config["asf-rest-config"]["api_version"].to_s puts "Salesforce url: " + asf_rest_config["asf-rest-config"]["url"].to_s puts "Username: " + username puts "Password: " + password puts "API Version " + login_svr security_token, rest_svr, rest_version = Salesforce::Rest::AsfRest.bootup_rest_adapter(username, password, api_version) puts 'Security Token: ' + security_token puts 'rest_svr: ' + rest_svr puts 'rest_version: ' + rest_version when"omni_auth" then consumer_key = asf_rest_config["asf-rest-config"]["consumer_key"] consumer_secret = asf_rest_config["asf-rest-config"]["consumer_secret"] puts "Salesforce consumer_key is:" + consumer_key.to_s puts "Salesforce consumser_secret is: " + consumer_secret.to_s Rails.application.config.middleware.use OmniAuth::Builder do provider :forcedotcom, consumer_key, consumer_secret end end rescue Exception => e puts e. end end end end |