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.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth_path ⇒ Object
Returns the value of attribute auth_path.
-
#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
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
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Facebook
Returns a new instance of Facebook.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sorcery/providers/facebook.rb', line 16 def initialize super @site = 'https://graph.facebook.com' @auth_site = 'https://www.facebook.com' @user_info_path = 'me' @scope = 'email' @display = 'page' @token_url = 'oauth/access_token' @auth_path = 'dialog/oauth' @mode = :query @parse = :json @param_name = 'access_token' end |
Instance Attribute Details
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def @access_permissions end |
#api_version ⇒ Object
Returns the value of attribute api_version.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def api_version @api_version end |
#auth_path ⇒ Object
Returns the value of attribute auth_path.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def auth_path @auth_path end |
#display ⇒ Object
Returns the value of attribute display.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def display @display end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
12 13 14 |
# File 'lib/sorcery/providers/facebook.rb', line 12 def mode @mode end |
#param_name ⇒ Object (readonly)
Returns the value of attribute param_name.
12 13 14 |
# File 'lib/sorcery/providers/facebook.rb', line 12 def param_name @param_name end |
#parse ⇒ Object
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.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def token_url @token_url end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
13 14 15 |
# File 'lib/sorcery/providers/facebook.rb', line 13 def user_info_path @user_info_path end |
Instance Method Details
#authorize_url ⇒ Object
overrides oauth2#authorize_url to allow customized scope.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sorcery/providers/facebook.rb', line 47 def # Fix: replace default oauth2 options, specially to prevent the Faraday gem which # concatenates with "/", removing the Facebook api version = { site: File.join(@site, api_version.to_s), authorize_url: File.join(@auth_site, api_version.to_s, auth_path), token_url: token_url } @scope = .present? ? .join(',') : scope super() end |
#get_user_hash(access_token) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/sorcery/providers/facebook.rb', line 31 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) 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.
42 43 44 |
# File 'lib/sorcery/providers/facebook.rb', line 42 def login_url(_params, _session) end |
#process_callback(params, _session) ⇒ Object
tries to login the user from access token
61 62 63 64 65 66 67 68 |
# File 'lib/sorcery/providers/facebook.rb', line 61 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 |