mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:34:31 +08:00
REFACTOR: Initialize auth providers after plugin.activate!
Also added some helpful functionality for plugin developers: - Raises RuntimeException if the auth provider has been registered too late - Logs use of deprecated parameters
This commit is contained in:
@ -25,8 +25,8 @@ class Plugin::Instance
|
||||
|
||||
# Memoized array readers
|
||||
[:assets,
|
||||
:auth_providers,
|
||||
:color_schemes,
|
||||
:before_auth_initializers,
|
||||
:initializers,
|
||||
:javascripts,
|
||||
:locales,
|
||||
@ -287,6 +287,11 @@ class Plugin::Instance
|
||||
initializers << block
|
||||
end
|
||||
|
||||
def before_auth(&block)
|
||||
raise "Auth providers must be registered before omniauth middleware. after_initialize is too late!" if @before_auth_complete
|
||||
before_auth_initializers << block
|
||||
end
|
||||
|
||||
# A proxy to `DiscourseEvent.on` which does nothing if the plugin is disabled
|
||||
def on(event_name, &block)
|
||||
DiscourseEvent.on(event_name) do |*args|
|
||||
@ -313,6 +318,13 @@ class Plugin::Instance
|
||||
end
|
||||
end
|
||||
|
||||
def notify_before_auth
|
||||
before_auth_initializers.each do |callback|
|
||||
callback.call(self)
|
||||
end
|
||||
@before_auth_complete = true
|
||||
end
|
||||
|
||||
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
|
||||
def register_category_custom_field_type(name, type)
|
||||
reloadable_patch do |plugin|
|
||||
@ -458,7 +470,6 @@ class Plugin::Instance
|
||||
register_assets! unless assets.blank?
|
||||
register_locales!
|
||||
register_service_workers!
|
||||
register_auth_providers!
|
||||
|
||||
seed_data.each do |key, value|
|
||||
DiscoursePluginRegistry.register_seed_data(key, value)
|
||||
@ -496,13 +507,13 @@ class Plugin::Instance
|
||||
end
|
||||
|
||||
def auth_provider(opts)
|
||||
provider = Auth::AuthProvider.new
|
||||
before_auth do
|
||||
provider = Auth::AuthProvider.new
|
||||
|
||||
Auth::AuthProvider.auth_attributes.each do |sym|
|
||||
provider.send "#{sym}=", opts.delete(sym)
|
||||
end
|
||||
Auth::AuthProvider.auth_attributes.each do |sym|
|
||||
provider.send "#{sym}=", opts.delete(sym)
|
||||
end
|
||||
|
||||
after_initialize do
|
||||
begin
|
||||
provider.authenticator.enabled?
|
||||
rescue NotImplementedError
|
||||
@ -513,9 +524,9 @@ class Plugin::Instance
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
auth_providers << provider
|
||||
DiscoursePluginRegistry.register_auth_provider(provider)
|
||||
end
|
||||
end
|
||||
|
||||
# shotgun approach to gem loading, in future we need to hack bundler
|
||||
@ -594,12 +605,6 @@ class Plugin::Instance
|
||||
end
|
||||
end
|
||||
|
||||
def register_auth_providers!
|
||||
auth_providers.each do |auth_provider|
|
||||
DiscoursePluginRegistry.register_auth_provider(auth_provider)
|
||||
end
|
||||
end
|
||||
|
||||
def register_locales!
|
||||
root_path = File.dirname(@path)
|
||||
|
||||
|
Reference in New Issue
Block a user