Module: TinyAdmin::Plugins::SimpleAuth
- Defined in:
- lib/tiny_admin/plugins/simple_auth.rb
Defined Under Namespace
Modules: InstanceMethods
Class Method Summary collapse
Class Method Details
.configure(app, opts = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tiny_admin/plugins/simple_auth.rb', line 9 def configure(app, opts = {}) @@opts = opts || {} # rubocop:disable Style/ClassVars @@opts[:password] ||= ENV.fetch('ADMIN_PASSWORD_HASH', nil) # NOTE: fallback value Warden::Strategies.add(:secret) do def authenticate! secret = params['secret'] || '' return fail(:invalid_credentials) if Digest::SHA512.hexdigest(secret) != @@opts[:password] success!(app: 'TinyAdmin') end end app.opts[:login_form] = opts[:login_form] || TinyAdmin::Views::Pages::SimpleAuthLogin app.use Warden::Manager do |manager| manager.default_strategies :secret manager.failure_app = TinyAdmin::Authentication end end |