Sha256: 2f44973ed709e7452275b8b56d20d8b2a7832492842a0b4e83e8e4b9d1599fd5

Contents?: true

Size: 715 Bytes

Versions: 7

Compression:

Stored size: 715 Bytes

Contents

require 'rest-core/middleware'

class RestCore::Oauth2Header
  def self.members; [:access_token_type, :access_token]; end
  include RestCore::Middleware

  def call env
    start_time = Time.now
    headers = {'Authorization' =>
                 "#{access_token_type(env)} #{access_token(env)}"}.
                merge(env[REQUEST_HEADERS] || {}) if access_token(env)

    event = Event::WithHeader.new(Time.now - start_time,
              "Authorization: #{headers['Authorization']}") if headers

    app.call(log(cache_key(
      env.merge(REQUEST_HEADERS => headers || env[REQUEST_HEADERS])), event))
  end

  def cache_key env
    env.merge('cache.key' => "#{request_uri(env)}&#{access_token(env)}")
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rest-core-1.0.3 lib/rest-core/middleware/oauth2_header.rb
rest-core-1.0.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-1.0.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-1.0.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.8.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.8.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-0.8.0 lib/rest-core/middleware/oauth2_header.rb