class LHC::Auth
Public Instance Methods
before_request(request)
click to toggle source
# File lib/lhc-core-interceptors/auth.rb, line 3 def before_request(request) options = request.options[:auth] || {} authenticate!(request, options) end
Private Instance Methods
authenticate!(request, options)
click to toggle source
# File lib/lhc-core-interceptors/auth.rb, line 10 def authenticate!(request, options) if options[:bearer] bearer_authentication!(request, options) elsif options[:basic] basic_authentication!(request, options) end end
basic_authentication!(request, options)
click to toggle source
# File lib/lhc-core-interceptors/auth.rb, line 18 def basic_authentication!(request, options) auth = options[:basic] credentials = "#{auth[:username]}:#{auth[:password]}" set_authorization_header request, "Basic #{Base64.encode64(credentials).chomp}" end
bearer_authentication!(request, options)
click to toggle source
# File lib/lhc-core-interceptors/auth.rb, line 24 def bearer_authentication!(request, options) token = options[:bearer] token = token.call if token.is_a?(Proc) set_authorization_header request, "Bearer #{token}" end