2 class Request::Authorization < Faraday::Middleware
3 KEY = "Authorization".freeze unless defined? KEY
6 def self.header(type, token)
11 build_hash(type.to_s, token)
13 raise ArgumentError, "Can't build an Authorization #{type} header from #{token.inspect}"
18 def self.build_hash(type, hash)
19 offset = KEY.size + type.size + 3
20 comma = ",\n#{' ' * offset}"
22 hash.each do |key, value|
23 values << "#{key}=#{value.to_s.inspect}"
25 "#{type} #{values * comma}"
28 def initialize(app, type, token)
29 @header_value = self.class.header(type, token)
35 unless env.request_headers[KEY]
36 env.request_headers[KEY] = @header_value