class FaradayMiddleware::FlowAccountOAuth2
Public Class Methods
new(app, client_id, access_token=nil)
click to toggle source
# File lib/faraday/oauth2.rb, line 30 def initialize(app, client_id, access_token=nil) @app = app @client_id = client_id @access_token = access_token end
Public Instance Methods
call(env)
click to toggle source
# File lib/faraday/oauth2.rb, line 6 def call(env) if env[:method] == :get or env[:method] == :delete if env[:url].query.nil? query = {} else query = Faraday::Utils.parse_query(env[:url].query) end if @access_token and not query["client_secret"] env[:request_headers] = env[:request_headers].merge("Authorization" => "Bearer #{@access_token}") end else # :POST, :PUT if @access_token and not env[:body] && JSON.parse(env[:body])["client_secret"] env[:body] = {} if env[:body].nil? env[:request_headers] = env[:request_headers].merge( "Authorization" => "Bearer " + @access_token, "Content-Type" => "application/json" ) end end @app.call env end