class AquaIo::HttpClient::AuthHandler
AuthHandler
takes care of devising the auth type and using it
Constants
- URL_SECRET
- URL_TOKEN
Public Class Methods
new(app, auth = {}, options = {})
click to toggle source
Calls superclass method
# File lib/aqua_io/http_client/auth_handler.rb, line 13 def initialize(app, auth = {}, options = {}) @auth = auth super(app) end
Public Instance Methods
call(env)
click to toggle source
# File lib/aqua_io/http_client/auth_handler.rb, line 18 def call(env) if !@auth.empty? auth = get_auth_type flag = false if auth == URL_SECRET env = url_secret(env) flag = true end if auth == URL_TOKEN env = url_token(env) flag = true end if !flag raise StandardError.new "Unable to calculate authorization method. Please check" end end @app.call(env) end
get_auth_type()
click to toggle source
Calculating the Authentication Type
# File lib/aqua_io/http_client/auth_handler.rb, line 42 def get_auth_type() if @auth.has_key?(:client_id) and @auth.has_key?(:client_secret) return URL_SECRET end if @auth.has_key?(:access_token) return URL_TOKEN end return -1 end
merge_query(env, query)
click to toggle source
# File lib/aqua_io/http_client/auth_handler.rb, line 80 def merge_query(env, query) query = query.update query_params(env[:url]) env[:url].query = Faraday::Utils.build_query(query) return env end
query_params(url)
click to toggle source
# File lib/aqua_io/http_client/auth_handler.rb, line 72 def query_params(url) if url.query.nil? or url.query.empty? {} else Faraday::Utils.parse_query(url.query) end end
url_secret(env)
click to toggle source
OAUTH2 Authorization with client secret
# File lib/aqua_io/http_client/auth_handler.rb, line 56 def url_secret(env) query = { :client_id => @auth[:client_id], :client_secret => @auth[:client_secret] } merge_query(env, query) end
url_token(env)
click to toggle source
OAUTH2 Authorization with access token
# File lib/aqua_io/http_client/auth_handler.rb, line 66 def url_token(env) query = { :access_token => @auth[:access_token] } merge_query(env, query) end