class Balrog::Middleware
Public: Balrog
middleware that handles form submissions, checking the password against the configured hash, and setting a session variable if they match.
This is typically set up in an initialize when you run `rails g balrog:install`, and looks a bit like this:
Balrog::Middleware.setup do |config| config.set_password_hash '<bcrypt hash>' end
Methods that are called in response to specific application requests.
Public Class Methods
new(app)
click to toggle source
# File lib/balrog/middleware.rb, line 23 def initialize(app) @app = app end
setup() { |self| ... }
click to toggle source
# File lib/balrog/middleware.rb, line 41 def self.setup yield self end
Private Class Methods
set_domain_whitelist(*domains)
click to toggle source
# File lib/balrog/middleware.rb, line 58 def self.set_domain_whitelist(*domains) @@domain_whitelist = domains end
set_omniauth(provider, *args)
click to toggle source
# File lib/balrog/middleware.rb, line 51 def self.set_omniauth(provider, *args) @@omniauth_config = { provider: provider, args: args } end
set_password_hash(input)
click to toggle source
# File lib/balrog/middleware.rb, line 47 def self.set_password_hash(input) @@password_hash = BCrypt::Password.new(input) end
set_session_expiry(time_period)
click to toggle source
# File lib/balrog/middleware.rb, line 62 def self.set_session_expiry(time_period) @@session_length = time_period end
Public Instance Methods
call(env)
click to toggle source
# File lib/balrog/middleware.rb, line 27 def call(env) path = env["PATH_INFO"] method = env["REQUEST_METHOD"] if login_request?(path, method) password_login(env) elsif omniauth_request?(path, method) omniauthentication(env) elsif logout_request?(path, method) logout(env) else @app.call(env) end end
Private Instance Methods
login_request?(path, method)
click to toggle source
# File lib/balrog/middleware.rb, line 66 def login_request?(path, method) method == 'POST' && path == '/balrog/signin' end
logout_request?(path, method)
click to toggle source
# File lib/balrog/middleware.rb, line 76 def logout_request?(path, method) method == "DELETE" && path == '/balrog/logout' end
omniauth_request?(path, method)
click to toggle source
# File lib/balrog/middleware.rb, line 70 def omniauth_request?(path, method) omniauth_config && method == "GET" && path == "/auth/#{omniauth_config[:provider]}/callback" end