2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-07 10:39:06 -05:00
|
|
|
class Auth::TwitterAuthenticator < Auth::ManagedAuthenticator
|
2013-08-23 02:20:43 -04:00
|
|
|
def name
|
|
|
|
"twitter"
|
|
|
|
end
|
|
|
|
|
2018-07-23 11:51:57 -04:00
|
|
|
def enabled?
|
|
|
|
SiteSetting.enable_twitter_logins
|
|
|
|
end
|
|
|
|
|
2024-02-25 23:08:12 -05:00
|
|
|
def healthy?
|
|
|
|
connection =
|
|
|
|
Faraday.new(url: "https://api.twitter.com") do |config|
|
|
|
|
config.basic_auth(SiteSetting.twitter_consumer_key, SiteSetting.twitter_consumer_secret)
|
|
|
|
end
|
|
|
|
connection.post("/oauth2/token").status == 200
|
|
|
|
rescue Faraday::Error
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2018-07-27 07:28:51 -04:00
|
|
|
def after_authenticate(auth_token, existing_account: nil)
|
2018-12-07 10:39:06 -05:00
|
|
|
# Twitter sends a huge amount of data which we don't need, so ignore it
|
|
|
|
auth_token[:extra] = {}
|
|
|
|
super
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|
|
|
|
|
2013-08-25 21:04:16 -04:00
|
|
|
def register_middleware(omniauth)
|
|
|
|
omniauth.provider :twitter,
|
|
|
|
setup:
|
|
|
|
lambda { |env|
|
|
|
|
strategy = env["omniauth.strategy"]
|
|
|
|
strategy.options[:consumer_key] = SiteSetting.twitter_consumer_key
|
|
|
|
strategy.options[:consumer_secret] = SiteSetting.twitter_consumer_secret
|
|
|
|
}
|
|
|
|
end
|
2022-11-23 22:46:06 -05:00
|
|
|
|
|
|
|
# twitter doesn't return unverfied email addresses in the API
|
|
|
|
# https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials
|
|
|
|
def primary_email_verified?(auth_token)
|
|
|
|
true
|
|
|
|
end
|
2013-08-23 02:20:43 -04:00
|
|
|
end
|