lib/pardot/authentication.rb in ruby-pardot-1.3.2 vs lib/pardot/authentication.rb in ruby-pardot-1.4.0
- old
+ new
@@ -1,29 +1,40 @@
module Pardot
module Authentication
-
+ # @deprecated Use of username and password authentication is deprecated.
def authenticate
- resp = post "login", nil, nil, nil, :email => @email, :password => @password, :user_key => @user_key
- update_version(resp["version"]) if resp && resp["version"]
- @api_key = resp && resp["api_key"]
+ if using_salesforce_access_token?
+ raise 'Authentication not available when using Salesforce access token. See https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_oauth_and_connected_apps.htm for more information.'
+ end
+
+ warn '[DEPRECATION] Use of username and password authentication is deprecated in favor of Salesforce OAuth. See https://developer.pardot.com/kb/authentication/ for more information.'
+ resp = post 'login', nil, nil, nil, email: @email, password: @password, user_key: @user_key
+ update_version(resp['version']) if resp && resp['version']
+ @api_key = resp && resp['api_key']
end
-
+
def authenticated?
- @api_key != nil
+ !@api_key.nil? || !@salesforce_access_token.nil?
end
-
+
+ def using_salesforce_access_token?
+ @salesforce_access_token != nil
+ end
+
def reauthenticate
+ if using_salesforce_access_token?
+ raise 'Reauthentication not available when using Salesforce access token. See https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/oauth_refresh_token_flow.htm for more information.'
+ end
+
+ warn '[DEPRECATION] Use Salesforce OAuth to refresh the Salesforce access token. See https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/oauth_refresh_token_flow.htm for more information.'
@api_key = nil
authenticate
end
private
- def update_version version
- if version.is_a? Array
- version = version.last
- end
+ def update_version(version)
+ version = version.last if version.is_a? Array
@version = version if version.to_i > 3
end
-
end
end