class Johac::Connection::Middleware::Authorization

Adds Authorization header to all requests.

Public Class Methods

new(app, scheme, access_key, secret_key) click to toggle source
Calls superclass method
# File lib/johac/connection.rb, line 156
def initialize(app, scheme, access_key, secret_key)
  @scheme = scheme
  @access_key = access_key
  @secret_key = secret_key
  super(app)
end

Public Instance Methods

call(env) click to toggle source
# File lib/johac/connection.rb, line 163
def call(env)
  if auth = case @scheme
            when :basic then "Basic #{basic_auth_token}"
            when :hmac  then "hmac #{hmac_auth_token(env.url.path)}"
            end
    env[:request_headers]['Authorization'] = auth
  end
  @app.call(env)
end

Private Instance Methods

basic_auth_token() click to toggle source
# File lib/johac/connection.rb, line 175
def basic_auth_token
  Base64.strict_encode64("#{@access_key}:#{@secret_key}")
end
hmac_auth_token(token) click to toggle source

TODO: Need a hook for generating the value

# File lib/johac/connection.rb, line 180
def hmac_auth_token(token)
  OpenSSL::HMAC.hexdigest('sha1', @secret_key, token)
end