Module: LinkedIn::Helpers::Authorization

Included in:
Client
Defined in:
lib/linked_in/helpers/authorization.rb

Constant Summary collapse

DEFAULT_OAUTH2_OPTIONS =
{
  authorize_path: "/uas/oauth2/authorization",
  access_token_path: "/uas/oauth2/accessToken",
  api_host: "https://api.linkedin.com",
  auth_host: "https://www.linkedin.com"
}

Instance Method Summary collapse

Instance Method Details

#authorize_url(params = {}) ⇒ Object

A way to fetch the authorize_url request.

Parameters:

  • :redirect_uri
    • Where you want it to redirect to after

  • :scope
    • A list of member permissions you would like to



47
48
49
50
51
52
53
54
55
56
# File 'lib/linked_in/helpers/authorization.rb', line 47

def authorize_url(params={})
  # response_type param included by default by using the OAuth 2.0
  # auth_code strategy
  # client_id param included automatically by the OAuth 2.0 gem
  params[:state] ||= state
  params[:redirect_uri] ||= "http://localhost"
  oauth2_client.auth_code.authorize_url(params)
rescue OAuth2::Error => e
  raise LinkedIn::Errors::UnauthorizedError.new(e.code), e.description
end

#oauth2_clientObject



37
38
39
40
41
# File 'lib/linked_in/helpers/authorization.rb', line 37

def oauth2_client
  @oauth2_client ||= ::OAuth2::Client.new(@client_id,
                                          @client_secret,
                                          parse_oauth2_options)
end

#request_access_token(code, params = {}) ⇒ Object

Fetches the access_token given the auth_code fetched by navigating to ‘authorize_url` fetched the token.

Parameters:

  • :redirect_uri
    • Where you want to redirect after you have



62
63
64
65
66
67
68
69
70
# File 'lib/linked_in/helpers/authorization.rb', line 62

def request_access_token(code, params={})
  params[:redirect_uri] ||= "http://localhost"
  opts = {}
  opts[:mode] = :query
  opts[:param_name] = "oauth2_access_token"
  @access_token = oauth2_client.auth_code.get_token(code, params, opts)
rescue OAuth2::Error => e
  raise LinkedIn::Errors::UnauthorizedError.new(e.code), e.description
end

#set_access_token(token, options = {}) ⇒ Object

If one already has an access_token string, it can be set here and turned into an OAuth2::AccessToken object.



74
75
76
77
78
79
# File 'lib/linked_in/helpers/authorization.rb', line 74

def set_access_token(token, options={})
  options[:access_token] = token
  options[:mode] = :query
  options[:param_name] = "oauth2_access_token"
  @access_token = OAuth2::AccessToken.from_hash oauth2_client, options
end