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 33
def access_token
  @access_token ||= ::OAuth2::AccessToken.new(consumer, @auth_token, :expires_at => @expires_at)
end
authorize_from_access(atoken, expires_at) click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 37
def authorize_from_access(atoken, expires_at)
  @auth_token, @expires_at = atoken, expires_at
end
authorize_from_request(request_token, request_secret, verifier_or_pin) 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 27
def authorize_from_request(request_token, request_secret, verifier_or_pin)
  request_token = ::OAuth::RequestToken.new(consumer, request_token, request_secret)
  access_token  = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
  @auth_token, @auth_secret = access_token.token, access_token.secret
end
consumer() click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 14
def consumer
  @consumer ||= ::OAuth2::Client.new(@consumer_token, @consumer_secret, parse_oauth_options)
end
request_token(options={}, *arguments, &block) click to toggle source

Note: If using oauth with a web app, be sure to provide :oauth_callback. Options:

:oauth_callback => String, url that LinkedIn should redirect to
# File lib/linked_in/helpers/authorization.rb, line 21
def request_token(options={}, *arguments, &block)
  @request_token ||= consumer.get_request_token(options, *arguments, &block)
end

Private Instance Methods

full_oauth_url_for(url_type, host_type) click to toggle source
# File lib/linked_in/helpers/authorization.rb, line 56
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 46
def parse_oauth_options
  {
      #:request_token_url => full_oauth_url_for(:request_token, :api_host),
      :access_token_url  => full_oauth_url_for(:access_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],
      :proxy             => @consumer_options.fetch(:proxy, nil)
  }
end