Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization middleware can't build a Bearer header from a lambda argument #1325

Closed
partydrone opened this issue Sep 15, 2021 · 3 comments · Fixed by #1322
Closed

Authorization middleware can't build a Bearer header from a lambda argument #1325

partydrone opened this issue Sep 15, 2021 · 3 comments · Fixed by #1322

Comments

@partydrone
Copy link

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
Copy link

jarl-dk commented Sep 15, 2021

Proc is only a 2.x feature (and only documented for 2.x). However help is on it's way in #1322

@iMacTia
Copy link
Member

iMacTia commented Sep 16, 2021

Thanks @jarl-dk for jumping on this!
I can't believe this feature was never asked before 😂, I added it in the 2.x branch (main) while refactoring but I never expected it to be so popular!

Let's keep this open and close it once we merge #1322 👍

@olleolleolle olleolleolle linked a pull request Sep 16, 2021 that will close this issue
3 tasks
@iMacTia
Copy link
Member

iMacTia commented Sep 18, 2021

This is now in the 1.x branch thanks to @jarl-dk and has just been released as v1.8.0 🎉

@iMacTia iMacTia closed this as completed Sep 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants