module LinkedIn::Helpers::Authorization

Constants

DEFAULT_OAUTH_OPTIONS

Public Instance Methods

access_token() click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 23
def access_token
  @access_token ||= ::OAuth2::AccessToken.new(consumer, @auth_token)
end
authorize_from_access(atoken) click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 31
def authorize_from_access(atoken)
  @auth_token = atoken
end
authorize_from_request(code, params = {}) click to toggle source

For web apps use params, for desktop apps, use the verifier is the pin that LinkedIn gives users.

# File lib/linked_in/helpers/authorization.rb, line 19
def authorize_from_request(code, params = {})
  @auth_token = consumer.auth_code.get_token(code, params).token
end
authorize_url(params = {}) click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 27
def authorize_url(params = {})
  consumer.auth_code.authorize_url(params)
end
consumer() click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 13
def consumer
  @consumer ||= ::OAuth2::Client.new(@consumer_token, @consumer_secret, parse_oauth_options)
end

Private Instance Methods

full_oauth_url_for(url_type, host_type) click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 49
def full_oauth_url_for(url_type, host_type)
  if @consumer_options["#{url_type}_url".to_sym]
    @consumer_options["#{url_type}_url".to_sym]
  else
    host = @consumer_options[:site] || @consumer_options[host_type] || DEFAULT_OAUTH_OPTIONS[host_type]
    path = @consumer_options[:"#{url_type}_path".to_sym] || DEFAULT_OAUTH_OPTIONS["#{url_type}_path".to_sym]
    "#{host}#{path}"
  end
end
parse_oauth_options() click to toggle source

since LinkedIn uses api.linkedin.com for request and access token exchanges, but www.linkedin.com for authorize/authenticate, we have to take care of the url creation ourselves.

# File lib/linked_in/helpers/authorization.rb, line 40
def parse_oauth_options
  {
    :token_url         => full_oauth_url_for(:token,     :api_host),
    :authorize_url     => full_oauth_url_for(:authorize, :auth_host),
    :site              => @consumer_options[:site] || @consumer_options[:api_host] || DEFAULT_OAUTH_OPTIONS[:api_host],
    :raise_errors      => false
  }
end