2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-07 06:31:04 -05:00
|
|
|
class Auth::GoogleOAuth2Authenticator < Auth::ManagedAuthenticator
|
2014-05-21 18:19:40 -04:00
|
|
|
def name
|
|
|
|
"google_oauth2"
|
|
|
|
end
|
|
|
|
|
2018-07-23 11:51:57 -04:00
|
|
|
def enabled?
|
|
|
|
SiteSetting.enable_google_oauth2_logins
|
|
|
|
end
|
|
|
|
|
2019-03-07 06:31:04 -05:00
|
|
|
def primary_email_verified?(auth_token)
|
|
|
|
# note, emails that come back from google via omniauth are always valid
|
|
|
|
# this protects against future regressions
|
|
|
|
auth_token[:extra][:raw_info][:email_verified]
|
2014-05-21 18:19:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def register_middleware(omniauth)
|
2018-02-22 18:19:36 -05:00
|
|
|
options = {
|
|
|
|
setup: lambda { |env|
|
|
|
|
strategy = env["omniauth.strategy"]
|
2019-01-31 05:05:25 -05:00
|
|
|
strategy.options[:client_id] = SiteSetting.google_oauth2_client_id
|
|
|
|
strategy.options[:client_secret] = SiteSetting.google_oauth2_client_secret
|
|
|
|
|
|
|
|
if (google_oauth2_hd = SiteSetting.google_oauth2_hd).present?
|
|
|
|
strategy.options[:hd] = google_oauth2_hd
|
|
|
|
end
|
|
|
|
|
|
|
|
if (google_oauth2_prompt = SiteSetting.google_oauth2_prompt).present?
|
|
|
|
strategy.options[:prompt] = google_oauth2_prompt.gsub("|", " ")
|
|
|
|
end
|
2019-03-07 06:31:04 -05:00
|
|
|
}
|
2018-02-22 18:19:36 -05:00
|
|
|
}
|
|
|
|
omniauth.provider :google_oauth2, options
|
2014-05-21 18:19:40 -04:00
|
|
|
end
|
2015-04-24 13:10:43 -04:00
|
|
|
end
|