Class: Sorcery::Providers::Facebook
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/facebook.rb
Overview
This class adds support for OAuth with facebook.com.
config.facebook.key = <key>
config.facebook.secret = <secret>
...
Instance Attribute Summary collapse
-
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
-
#display ⇒ Object
Returns the value of attribute display.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#param_name ⇒ Object
readonly
Returns the value of attribute param_name.
-
#parse ⇒ Object
readonly
Returns the value of attribute parse.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
-
#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
-
#authorize_url ⇒ Object
overrides oauth2#authorize_url to allow customized scope.
- #get_user_hash(access_token) ⇒ Object
-
#initialize ⇒ Facebook
constructor
A new instance of Facebook.
-
#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::Oauth2
#build_client, #get_access_token, #oauth_version
Methods inherited from Base
descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Facebook
Returns a new instance of Facebook.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sorcery/providers/facebook.rb', line 17 def initialize super @site = 'https://graph.facebook.com' @user_info_path = '/me' @scope = 'email,offline_access' @display = 'page' @token_url = 'oauth/access_token' @mode = :query @parse = :query @param_name = 'access_token' end |
Instance Attribute Details
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
14 15 16 |
# File 'lib/sorcery/providers/facebook.rb', line 14 def @access_permissions end |
#display ⇒ Object
Returns the value of attribute display.
14 15 16 |
# File 'lib/sorcery/providers/facebook.rb', line 14 def display @display end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def mode @mode end |
#param_name ⇒ Object (readonly)
Returns the value of attribute param_name.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def param_name @param_name end |
#parse ⇒ Object (readonly)
Returns the value of attribute parse.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def parse @parse end |
#scope ⇒ Object
Returns the value of attribute scope.
14 15 16 |
# File 'lib/sorcery/providers/facebook.rb', line 14 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
14 15 16 |
# File 'lib/sorcery/providers/facebook.rb', line 14 def token_url @token_url end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
14 15 16 |
# File 'lib/sorcery/providers/facebook.rb', line 14 def user_info_path @user_info_path end |
Instance Method Details
#authorize_url ⇒ Object
overrides oauth2#authorize_url to allow customized scope.
46 47 48 49 |
# File 'lib/sorcery/providers/facebook.rb', line 46 def @scope = .present? ? .join(',') : scope super end |
#get_user_hash(access_token) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/sorcery/providers/facebook.rb', line 30 def get_user_hash(access_token) response = access_token.get(user_info_path) {}.tap do |h| h[:user_info] = JSON.parse(response.body) h[:uid] = h[:user_info]['id'] 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 |
# File 'lib/sorcery/providers/facebook.rb', line 41 def login_url(params, session) end |
#process_callback(params, session) ⇒ Object
tries to login the user from access token
52 53 54 55 56 57 58 59 |
# File 'lib/sorcery/providers/facebook.rb', line 52 def process_callback(params, session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token(args, token_url: token_url, mode: mode, param_name: param_name, parse: parse) end |