Class: Sorcery::Providers::Xing
- Includes:
- Sorcery::Protocols::Oauth
- Defined in:
- lib/sorcery/providers/xing.rb
Overview
This class adds support for OAuth with xing.com.
config.xing.key = <key>
config.xing.secret = <secret>
...
Instance Attribute Summary collapse
-
#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_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 ⇒ Xing
constructor
A new instance of Xing.
-
#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
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Xing
Returns a new instance of Xing.
15 16 17 18 19 20 21 22 23 |
# File 'lib/sorcery/providers/xing.rb', line 15 def initialize @configuration = { site: 'https://api.xing.com/v1', authorize_path: '/authorize', request_token_path: '/request_token', access_token_path: '/access_token' } @user_info_path = '/users/me' end |
Instance Attribute Details
#access_token_path ⇒ Object
Returns the value of attribute access_token_path.
12 13 14 |
# File 'lib/sorcery/providers/xing.rb', line 12 def access_token_path @access_token_path end |
#authorize_path ⇒ Object
Returns the value of attribute authorize_path.
12 13 14 |
# File 'lib/sorcery/providers/xing.rb', line 12 def @authorize_path end |
#request_token_path ⇒ Object
Returns the value of attribute request_token_path.
12 13 14 |
# File 'lib/sorcery/providers/xing.rb', line 12 def request_token_path @request_token_path end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
12 13 14 |
# File 'lib/sorcery/providers/xing.rb', line 12 def user_info_path @user_info_path end |
Instance Method Details
#get_consumer ⇒ Object
Override included get_consumer method to provide authorize_path
26 27 28 |
# File 'lib/sorcery/providers/xing.rb', line 26 def get_consumer ::OAuth::Consumer.new(@key, @secret, @configuration) end |
#get_user_hash(access_token) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/sorcery/providers/xing.rb', line 30 def get_user_hash(access_token) response = access_token.get(user_info_path) auth_hash(access_token).tap do |h| h[:user_info] = JSON.parse(response.body)['users'].first 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.
41 42 43 44 45 46 |
# File 'lib/sorcery/providers/xing.rb', line 41 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
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sorcery/providers/xing.rb', line 49 def process_callback(params, session) args = { oauth_verifier: params[:oauth_verifier], request_token: session[:request_token], request_token_secret: session[:request_token_secret] } args[:code] = params[:code] if params[:code] get_access_token(args) end |