mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:14:12 +08:00
FEATURE: List, revoke and reconnect associated accounts. Phase 1 (#6099)
Listing connections is supported for all built-in auth providers. Revoke and reconnect is currently only implemented for Facebook.
This commit is contained in:
@ -8,7 +8,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||
BUILTIN_AUTH = [
|
||||
Auth::FacebookAuthenticator.new,
|
||||
Auth::GoogleOAuth2Authenticator.new,
|
||||
Auth::OpenIdAuthenticator.new("yahoo", "https://me.yahoo.com", trusted: true),
|
||||
Auth::OpenIdAuthenticator.new("yahoo", "https://me.yahoo.com", 'enable_yahoo_logins', trusted: true),
|
||||
Auth::GithubAuthenticator.new,
|
||||
Auth::TwitterAuthenticator.new,
|
||||
Auth::InstagramAuthenticator.new
|
||||
@ -18,10 +18,6 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||
|
||||
layout 'no_ember'
|
||||
|
||||
def self.types
|
||||
@types ||= Enum.new(:facebook, :instagram, :twitter, :google, :yahoo, :github, :persona, :cas)
|
||||
end
|
||||
|
||||
# need to be able to call this
|
||||
skip_before_action :check_xhr
|
||||
|
||||
@ -36,9 +32,13 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||
auth[:session] = session
|
||||
|
||||
authenticator = self.class.find_authenticator(params[:provider])
|
||||
provider = Discourse.auth_providers && Discourse.auth_providers.find { |p| p.name == params[:provider] }
|
||||
provider = DiscoursePluginRegistry.auth_providers.find { |p| p.name == params[:provider] }
|
||||
|
||||
@auth_result = authenticator.after_authenticate(auth)
|
||||
if authenticator.can_connect_existing_user? && current_user
|
||||
@auth_result = authenticator.after_authenticate(auth, existing_account: current_user)
|
||||
else
|
||||
@auth_result = authenticator.after_authenticate(auth)
|
||||
end
|
||||
|
||||
origin = request.env['omniauth.origin']
|
||||
|
||||
@ -91,23 +91,10 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||
end
|
||||
|
||||
def self.find_authenticator(name)
|
||||
BUILTIN_AUTH.each do |authenticator|
|
||||
if authenticator.name == name
|
||||
raise Discourse::InvalidAccess.new(I18n.t("provider_not_enabled")) unless SiteSetting.send("enable_#{name}_logins?")
|
||||
return authenticator
|
||||
end
|
||||
Discourse.enabled_authenticators.each do |authenticator|
|
||||
return authenticator if authenticator.name == name
|
||||
end
|
||||
|
||||
Discourse.auth_providers.each do |provider|
|
||||
next if provider.name != name
|
||||
|
||||
unless provider.enabled_setting.nil? || SiteSetting.send(provider.enabled_setting)
|
||||
raise Discourse::InvalidAccess.new(I18n.t("provider_not_enabled"))
|
||||
end
|
||||
return provider.authenticator
|
||||
end
|
||||
|
||||
raise Discourse::InvalidAccess.new(I18n.t("provider_not_found"))
|
||||
raise Discourse::InvalidAccess.new(I18n.t('authenticator_not_found'))
|
||||
end
|
||||
|
||||
protected
|
||||
|
Reference in New Issue
Block a user