class ZohoHub::Auth
Class that takes care of authentication using Oauth2 workflow as described here: www.zoho.com/crm/help/api/v2/#oauth-request.
Constants
- AUTH_PATH
- DEFAULT_ACCESS_TYPE
- DEFAULT_SCOPES
- REVOKE_TOKEN_PATH
- TOKEN_PATH
Public Class Methods
auth_url(access_type: DEFAULT_ACCESS_TYPE, scopes: DEFAULT_SCOPES)
click to toggle source
# File lib/zoho_hub/auth.rb, line 36 def self.auth_url(access_type: DEFAULT_ACCESS_TYPE, scopes: DEFAULT_SCOPES) new(access_type: access_type, scopes: scopes).auth_url end
get_token(grant_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 103 def self.get_token(grant_token) new.get_token(grant_token) end
new(access_type: DEFAULT_ACCESS_TYPE, scopes: DEFAULT_SCOPES)
click to toggle source
# File lib/zoho_hub/auth.rb, line 30 def initialize(access_type: DEFAULT_ACCESS_TYPE, scopes: DEFAULT_SCOPES) @configuration = ZohoHub.configuration @access_type = access_type @scopes = scopes end
refresh_token(refresh_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 63 def self.refresh_token(refresh_token) new.refresh_token(refresh_token) end
Public Instance Methods
auth_full_uri()
click to toggle source
# File lib/zoho_hub/auth.rb, line 59 def auth_full_uri Addressable::URI.join(api_domain, AUTH_PATH) end
auth_url()
click to toggle source
# File lib/zoho_hub/auth.rb, line 40 def auth_url uri = auth_full_uri query = { client_id: client_id, scope: @scopes.join(','), access_type: @access_type, redirect_uri: redirect_uri, response_type: 'code' } # The consent page must be presented otherwise we don't get the refresh token back. query[:prompt] = 'consent' if @access_type == DEFAULT_ACCESS_TYPE uri.query_values = query Addressable::URI.unencode(uri.to_s) end
get_token(grant_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 107 def get_token(grant_token) result = Faraday.post(token_url(grant_token)) parse(result.body) end
refresh_token(refresh_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 67 def refresh_token(refresh_token) result = Faraday.post(refresh_url(refresh_token)) json = parse(result.body) json.merge(refresh_token: refresh_token) end
refresh_url(refresh_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 74 def refresh_url(refresh_token) uri = token_full_uri uri.query_values = { client_id: client_id, client_secret: secret, refresh_token: refresh_token, grant_type: 'refresh_token' } Addressable::URI.unencode(uri.to_s) end
revoke_refresh_token(refresh_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 91 def revoke_refresh_token(refresh_token) uri = token_full_uri uri.query_values = { token: refresh_token } url = Addressable::URI.unencode(uri.to_s) result = Faraday.post(url) parse(result.body) end
token_full_uri()
click to toggle source
# File lib/zoho_hub/auth.rb, line 87 def token_full_uri Addressable::URI.join(api_domain, TOKEN_PATH) end
token_url(grant_token)
click to toggle source
# File lib/zoho_hub/auth.rb, line 113 def token_url(grant_token) uri = token_full_uri uri.query_values = { client_id: client_id, client_secret: secret, code: grant_token, redirect_uri: redirect_uri, grant_type: 'authorization_code' } Addressable::URI.unencode(uri.to_s) end
Private Instance Methods
parse(body)
click to toggle source
# File lib/zoho_hub/auth.rb, line 129 def parse(body) MultiJson.load(body, symbolize_keys: true) end