2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-28 10:49:24 -05:00
|
|
|
class Auth::FacebookAuthenticator < Auth::ManagedAuthenticator
|
2013-08-23 02:20:43 -04:00
|
|
|
|
2018-08-09 11:29:02 -04:00
|
|
|
AVATAR_SIZE ||= 480
|
2016-09-28 00:38:41 -04:00
|
|
|
|
2013-08-23 02:20:43 -04:00
|
|
|
def name
|
|
|
|
"facebook"
|
|
|
|
end
|
|
|
|
|
2018-07-23 11:51:57 -04:00
|
|
|
def enabled?
|
|
|
|
SiteSetting.enable_facebook_logins
|
|
|
|
end
|
|
|
|
|
2013-08-25 21:04:16 -04:00
|
|
|
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
|
2018-11-28 10:49:24 -05:00
|
|
|
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
|
2013-08-25 21:04:16 -04:00
|
|
|
},
|
|
|
|
scope: "email"
|
|
|
|
end
|
|
|
|
|
2022-11-23 22:46:06 -05:00
|
|
|
# facebook doesn't return unverified email addresses so it's safe to assume
|
|
|
|
# whatever email we get from them is verified
|
|
|
|
# https://developers.facebook.com/docs/graph-api/reference/user/
|
|
|
|
def primary_email_verified?(auth_token)
|
|
|
|
true
|
|
|
|
end
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|