Authorization middleware can't build a Bearer header from a lambda argument
partydrone opened this issue ยท 3 comments
partydrone commented
Basic Info
- Faraday Version: 1.7.2
- Ruby Version: 3.0.2
Issue description
Following the Authorization Middleware documentation, I am trying to pass a lambda as an argument for a bearer token, but I get an error instead:
/usr/local/bundle/gems/faraday-1.7.2/lib/faraday/request/authorization.rb:21:in `header': Can't build an Authorization Bearerheader from #<Proc:0x00005588d84bb188 /opt/gem/lib/keap/rest/connection.rb:75 (lambda)> (ArgumentError)
Steps to reproduce
Create a class with a connection
method that returns a Faraday::Client object configured with the Authorization middleware:
class Client
def connection
@connection ||= Faraday.new("https://api.infusionsoft.com/crm/rest/v1") do |http|
http.headers[:accept] = "application/json, */*"
http.request :authorization, :Bearer, -> { "my_secret_token" }
http.request :json
http.response :dates
http.response :json, content_type: "application/json"
http.adapter Faraday.default_adapter
end
end
Create a new instance of Client
and make a request:
client = Client.new
client.connection.get("account", {}, {})
To see the code in full context, check out my repo and look at:
jarl-dk commented
Proc is only a 2.x feature (and only documented for 2.x). However help is on it's way in #1322
iMacTia commented