class Transistor::Middleware::Authentication

Constants

AUTHORIZATION_HEADER
CONTENT_TYPE_HEADER

Public Instance Methods

call(env) click to toggle source
# File lib/transistor/middleware/authentication.rb, line 13
def call(env)
  env[:request_headers][AUTHORIZATION_HEADER] = authorize_request(env)
  @app.call(env)
end
initalize(app, options = {}) click to toggle source
Calls superclass method
# File lib/transistor/middleware/authentication.rb, line 9
def initalize(app, options = {})
  super(app)
end

Private Instance Methods

authorize_request(env) click to toggle source
# File lib/transistor/middleware/authentication.rb, line 20
def authorize_request(env)
  Hawk::Client.build_authorization_header(
    credentials: Transistor.config.credentials,
    ts: Time.now.to_i,
    content_type: env[:request_headers][CONTENT_TYPE_HEADER].to_s.split(';').first,
    method: env[:method].to_s.upcase,
    port: env[:url].port || (env[:url].scheme == 'https' ? 443 : 80),
    host: env[:url].host,
    request_uri: env[:url].to_s.sub(%r{\A#{env[:url].scheme}://#{env[:url].host}(:#{env[:url].port})?}, '')
  )
end