Class: SignalWire::AgentBase::AgentTimingSafeBasicAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/agent/agent_base.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, agent) ⇒ AgentTimingSafeBasicAuth

Returns a new instance of AgentTimingSafeBasicAuth.



2096
2097
2098
2099
# File 'lib/signalwire/agent/agent_base.rb', line 2096

def initialize(app, agent)
  @app   = app
  @agent = agent
end

Instance Method Details

#call(env) ⇒ Object



2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
# File 'lib/signalwire/agent/agent_base.rb', line 2101

def call(env)
  auth = Rack::Auth::Basic::Request.new(env)
  unless auth.provided? && auth.basic?
    return _unauthorized
  end

  user, pass = @agent.get_basic_auth_credentials
  input_user, input_pass = auth.credentials

  user_ok = Rack::Utils.secure_compare(user.to_s, input_user.to_s)
  pass_ok = Rack::Utils.secure_compare(pass.to_s, input_pass.to_s)

  if user_ok && pass_ok
    @app.call(env)
  else
    _unauthorized
  end
end