Sha256: 7b4f608906d6a6e13a4d1b169ae8b53390644809b866f66ec6d8dbb0c50aa067

Contents?: true

Size: 851 Bytes

Versions: 23

Compression:

Stored size: 851 Bytes

Contents

require 'rest-core/middleware'

# http://tools.ietf.org/html/rfc6749
class RestCore::Oauth2Header
  def self.members; [:access_token_type, :access_token]; end
  include RestCore::Middleware

  def call env, &k
    start_time = Time.now
    headers    = build_headers(env)
    auth       = headers['Authorization']
    event      = Event::WithHeader.new(Time.now - start_time,
                   "Authorization: #{auth}") if auth

    app.call(log(env.merge(REQUEST_HEADERS => headers), event), &k)
  end

  def build_headers env
    auth = case token = access_token(env)
           when String
             token
           when Hash
            token.map{ |(k, v)| "#{k}=\"#{v}\"" }.join(', ')
           end

    if auth
      {'Authorization' => "#{access_token_type(env)} #{auth}"}
    else
      {}
    end.merge(env[REQUEST_HEADERS])
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rest-core-3.6.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.92 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.91 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.9 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.8 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.7 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.6 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.5 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.4 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.3 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.5.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.4.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.4.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.3.3 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.3.2 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.3.1 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.3.0 lib/rest-core/middleware/oauth2_header.rb
rest-core-3.2.0 lib/rest-core/middleware/oauth2_header.rb