2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-28 23:49:24 +08:00
|
|
|
class Auth::FacebookAuthenticator < Auth::ManagedAuthenticator
|
2013-08-23 14:20:43 +08:00
|
|
|
|
2018-08-09 23:29:02 +08:00
|
|
|
AVATAR_SIZE ||= 480
|
2016-09-28 12:38:41 +08:00
|
|
|
|
2013-08-23 14:20:43 +08:00
|
|
|
def name
|
|
|
|
"facebook"
|
|
|
|
end
|
|
|
|
|
2018-07-23 23:51:57 +08:00
|
|
|
def enabled?
|
|
|
|
SiteSetting.enable_facebook_logins
|
|
|
|
end
|
|
|
|
|
2013-08-26 09:04:16 +08: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 23:49:24 +08: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-26 09:04:16 +08:00
|
|
|
},
|
|
|
|
scope: "email"
|
|
|
|
end
|
|
|
|
|
2013-08-23 14:20:43 +08:00
|
|
|
end
|