Class: Auth::FacebookAuthenticator

Inherits:
ManagedAuthenticator show all
Defined in:
lib/auth/facebook_authenticator.rb

Instance Method Summary collapse

Methods inherited from ManagedAuthenticator

#after_authenticate, #after_create_account, #always_update_user_email?, #can_connect_existing_user?, #can_revoke?, #description_for_auth_hash, #description_for_user, #find_user_by_email, #find_user_by_username, #is_managed?, #match_by_email, #match_by_username, #retrieve_avatar, #retrieve_profile, #revoke

Methods inherited from Authenticator

#after_authenticate, #after_create_account, #can_connect_existing_user?, #can_revoke?, #description_for_auth_hash, #description_for_user, #provides_groups?, #revoke

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/auth/facebook_authenticator.rb', line 10

def enabled?
  SiteSetting.enable_facebook_logins
end

#nameObject



6
7
8
# File 'lib/auth/facebook_authenticator.rb', line 6

def name
  "facebook"
end

#primary_email_verified?(auth_token) ⇒ Boolean

facebook doesn’t return unverified email addresses so it’s safe to assume whatever email we get from them is verified developers.facebook.com/docs/graph-api/reference/user/

Returns:

  • (Boolean)


34
35
36
# File 'lib/auth/facebook_authenticator.rb', line 34

def primary_email_verified?(auth_token)
  true
end

#register_middleware(omniauth) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/auth/facebook_authenticator.rb', line 14

def register_middleware(omniauth)
  omniauth.provider :facebook,
                    setup:
                      lambda { |env|
                        strategy = env["omniauth.strategy"]
                        strategy.options[:client_id] = SiteSetting.facebook_app_id
                        strategy.options[:client_secret] = SiteSetting.facebook_app_secret
                        strategy.options[:info_fields] = "name,first_name,last_name,email"
                        strategy.options[:image_size] = {
                          width: AVATAR_SIZE,
                          height: AVATAR_SIZE,
                        }
                        strategy.options[:secure_image_url] = true
                      },
                    scope: "email"
end