Class: Auth::TwitterAuthenticator

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

Instance Method Summary collapse

Methods inherited from ManagedAuthenticator

#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_create_account, #can_connect_existing_user?, #can_revoke?, #description_for_auth_hash, #description_for_user, #provides_groups?, #revoke

Instance Method Details

#after_authenticate(auth_token, existing_account: nil) ⇒ Object



22
23
24
25
26
# File 'lib/auth/twitter_authenticator.rb', line 22

def after_authenticate(auth_token, existing_account: nil)
  # Twitter sends a huge amount of data which we don't need, so ignore it
  auth_token[:extra] = {}
  super
end

#enabled?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/auth/twitter_authenticator.rb', line 8

def enabled?
  SiteSetting.enable_twitter_logins
end

#healthy?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/auth/twitter_authenticator.rb', line 12

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

#nameObject



4
5
6
# File 'lib/auth/twitter_authenticator.rb', line 4

def name
  "twitter"
end

#primary_email_verified?(auth_token) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/auth/twitter_authenticator.rb', line 40

def primary_email_verified?(auth_token)
  true
end

#register_middleware(omniauth) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/auth/twitter_authenticator.rb', line 28

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