mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
REFACTOR: Serve auth provider information in the site serializer.
At the moment core providers are hard-coded in Javascript, and plugin providers get added to the JS payload at compile time. This refactor means that we only ship enabled providers to the client.
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
class Plugin::AuthProvider
|
||||
|
||||
def self.auth_attributes
|
||||
[:glyph, :background_color, :pretty_name, :title, :message, :frame_width, :frame_height, :authenticator,
|
||||
:pretty_name_setting, :title_setting, :enabled_setting, :full_screen_login, :full_screen_login_setting,
|
||||
:custom_url]
|
||||
end
|
||||
|
||||
attr_accessor(*auth_attributes)
|
||||
|
||||
def name
|
||||
authenticator.name
|
||||
end
|
||||
|
||||
def to_json
|
||||
result = { name: name }
|
||||
result['customUrl'] = custom_url if custom_url
|
||||
result['prettyNameOverride'] = pretty_name || name
|
||||
result['titleOverride'] = title if title
|
||||
result['titleSetting'] = title_setting if title_setting
|
||||
result['prettyNameSetting'] = pretty_name_setting if pretty_name_setting
|
||||
result['enabledSetting'] = enabled_setting if enabled_setting
|
||||
result['messageOverride'] = message if message
|
||||
result['frameWidth'] = frame_width if frame_width
|
||||
result['frameHeight'] = frame_height if frame_height
|
||||
result['fullScreenLogin'] = full_screen_login if full_screen_login
|
||||
result['fullScreenLoginSetting'] = full_screen_login_setting if full_screen_login_setting
|
||||
result.to_json
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'digest/sha1'
|
||||
require 'fileutils'
|
||||
require_dependency 'plugin/metadata'
|
||||
require_dependency 'plugin/auth_provider'
|
||||
require_dependency 'lib/auth'
|
||||
|
||||
class Plugin::CustomEmoji
|
||||
def self.cache_key
|
||||
@@ -393,38 +393,6 @@ class Plugin::Instance
|
||||
css = styles.join("\n")
|
||||
js = javascripts.join("\n")
|
||||
|
||||
auth_providers.each do |auth|
|
||||
|
||||
auth_json = auth.to_json
|
||||
hash = Digest::SHA1.hexdigest(auth_json)
|
||||
js << <<JS
|
||||
define("discourse/initializers/login-method-#{hash}",
|
||||
["discourse/models/login-method", "exports"],
|
||||
function(module, __exports__) {
|
||||
"use strict";
|
||||
__exports__["default"] = {
|
||||
name: "login-method-#{hash}",
|
||||
after: "inject-objects",
|
||||
initialize: function(container) {
|
||||
if (Ember.testing) { return; }
|
||||
|
||||
var authOpts = #{auth_json};
|
||||
authOpts.siteSettings = container.lookup('site-settings:main');
|
||||
module.register(authOpts);
|
||||
}
|
||||
};
|
||||
});
|
||||
JS
|
||||
|
||||
if auth.glyph
|
||||
css << ".btn-social.#{auth.name}:before{ content: '#{auth.glyph}'; }\n"
|
||||
end
|
||||
|
||||
if auth.background_color
|
||||
css << ".btn-social.#{auth.name}{ background: #{auth.background_color}; }\n"
|
||||
end
|
||||
end
|
||||
|
||||
# Generate an IIFE for the JS
|
||||
js = "(function(){#{js}})();" if js.present?
|
||||
|
||||
@@ -495,9 +463,9 @@ JS
|
||||
end
|
||||
|
||||
def auth_provider(opts)
|
||||
provider = Plugin::AuthProvider.new
|
||||
provider = Auth::AuthProvider.new
|
||||
|
||||
Plugin::AuthProvider.auth_attributes.each do |sym|
|
||||
Auth::AuthProvider.auth_attributes.each do |sym|
|
||||
provider.send "#{sym}=", opts.delete(sym)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user