Class: Sorcery::Providers::Linkedin
- Includes:
- Sorcery::Protocols::Oauth
- Defined in:
- lib/sorcery/providers/linkedin.rb
Overview
This class adds support for OAuth with Linkedin.com.
config.linkedin.key = <key>
config.linkedin.secret = <secret>
...
Instance Attribute Summary collapse
-
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
-
#access_token_path ⇒ Object
Returns the value of attribute access_token_path.
-
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
-
#request_token_path ⇒ Object
Returns the value of attribute request_token_path.
-
#user_info_fields ⇒ Object
Returns the value of attribute user_info_fields.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Instance Method Summary collapse
-
#get_consumer ⇒ Object
Override included get_consumer method to provide authorize_path.
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Linkedin
constructor
A new instance of Linkedin.
-
#login_url(params, session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
-
#process_callback(params, session) ⇒ Object
tries to login the user from access token.
Methods included from Sorcery::Protocols::Oauth
#authorize_url, #get_access_token, #get_request_token, #oauth_version
Methods inherited from Base
descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Linkedin
Returns a new instance of Linkedin.
16 17 18 19 20 21 22 23 24 |
# File 'lib/sorcery/providers/linkedin.rb', line 16 def initialize @configuration = { site: 'https://api.linkedin.com', authorize_path: '/uas/oauth/authenticate', request_token_path: '/uas/oauth/requestToken', access_token_path: '/uas/oauth/accessToken' } @user_info_path = '/v1/people/~' end |
Instance Attribute Details
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def @access_permissions end |
#access_token_path ⇒ Object
Returns the value of attribute access_token_path.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def access_token_path @access_token_path end |
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def @authorize_path end |
#request_token_path ⇒ Object
Returns the value of attribute request_token_path.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def request_token_path @request_token_path end |
#user_info_fields ⇒ Object
Returns the value of attribute user_info_fields.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def user_info_fields @user_info_fields end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
13 14 15 |
# File 'lib/sorcery/providers/linkedin.rb', line 13 def user_info_path @user_info_path end |
Instance Method Details
#get_consumer ⇒ Object
Override included get_consumer method to provide authorize_path
27 28 29 30 31 |
# File 'lib/sorcery/providers/linkedin.rb', line 27 def get_consumer # Add access permissions to request token path @configuration[:request_token_path] += '?scope=' + .join('+') unless .blank? or @configuration[:request_token_path].include? '?scope=' ::OAuth::Consumer.new(@key, @secret, @configuration) end |
#get_user_hash(access_token) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/sorcery/providers/linkedin.rb', line 33 def get_user_hash(access_token) fields = self.user_info_fields.join(',') response = access_token.get("#{@user_info_path}:(#{fields})", 'x-li-format' => 'json') {}.tap do |h| h[:user_info] = JSON.parse(response.body) h[:uid] = h[:user_info]['id'].to_s end end |
#login_url(params, session) ⇒ Object
calculates and returns the url to which the user should be redirected, to get authenticated at the external provider’s site.
45 46 47 48 49 50 |
# File 'lib/sorcery/providers/linkedin.rb', line 45 def login_url(params, session) req_token = get_request_token session[:request_token] = req_token.token session[:request_token_secret] = req_token.secret ({ request_token: req_token.token, request_token_secret: req_token.secret }) end |
#process_callback(params, session) ⇒ Object
tries to login the user from access token
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sorcery/providers/linkedin.rb', line 53 def process_callback(params, session) args = { oauth_verifier: params[:oauth_verifier], request_token: session[:request_token], request_token_secret: session[:request_token_secret] } args.merge!({ code: params[:code] }) if params[:code] get_access_token(args) end |