class RestCore::Oauth2Header

tools.ietf.org/html/rfc6749

Public Class Methods

members() click to toggle source
# File lib/rest-core/middleware/oauth2_header.rb, line 7
def self.members; [:access_token_type, :access_token]; end

Public Instance Methods

build_headers(env) click to toggle source
# File lib/rest-core/middleware/oauth2_header.rb, line 20
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
call(env, &k) click to toggle source
# File lib/rest-core/middleware/oauth2_header.rb, line 10
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