-
Notifications
You must be signed in to change notification settings - Fork 981
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
WARNING: Faraday::Connection#basic_auth
is deprecated
#1317
Comments
The docs are wrong :) I just opened a PR to fix that. In the meantime you need to use it like this: http = Faraday.new do |conn|
conn.request(:basic_auth, 'username', 'password')
end |
Hello! The context for the documentation website not rhyming with the 1.x deprecation message is: "all the website documents is the upcoming 2.0". That version where the old way is removed. The context is only ever mentioned only in the README - this is a weakness, which we'd love to get concrete help with on the website front. Link to that part: https://github.com/lostisland/faraday#attention |
@peterberkenbosch is correct, that's the right way to use the middleware in Faraday 1.x, while the documentation is showing the correct usage for the upcoming v2.0. Sorry about the confusion, this is not the first time an issue like this has been raised. I'll be looking at a quick solution to make things clearer |
Thank you! All good now. ❤️ |
Hello @iMacTia, I still have problem on this issue. I originally created a connection like this client = Faraday.new(url: url) do |faraday|
faraday.headers["Accept"] = "application/json"
faraday.headers["X-Version"] = "2"
faraday.headers["Authorization"] = "token #{token}"
faraday.request(:json)
faraday.response(:json, content_type: /\bjson$/)
faraday.adapter(Faraday.default_adapter)
end Based on the above talk, I guess if I switch to use faraday.request(:token_auth, token), it should help add header in the request, so I switched to client = Faraday.new(url: url) do |faraday|
faraday.headers["Accept"] = "application/json"
faraday.headers["X-Version"] = "2"
faraday.request(:token_auth, token)
faraday.request(:json)
faraday.response(:json, content_type: /\bjson$/)
faraday.adapter(Faraday.default_adapter)
end The above client is used in this way and I got error
I also debugged the code and somehow, middleware didn't take effect in the request and no
Did I use it in a wrong way or should I create a new bug? BTW, what is the difference between |
Hi @xiaoxipang, lot's of good questions in there, let me see if I can answer them all.
You used it correctly, but I suspect the output of the middleware is not exactly what the server is expecting. client = Faraday.new(url: url) do |faraday|
# This header is not necessary, it will be set by the json middleware
# faraday.headers["Accept"] = "application/json"
faraday.headers["X-Version"] = "2"
faraday.request(:authorization, 'Token', token)
faraday.request(:json)
faraday.response(:json, content_type: /\bjson$/)
faraday.adapter(Faraday.default_adapter)
end This will set the header correctly to
That is strange, I just tested the code above and it works as expected for me. Seeing the client.get('https://google.co.uk')
=> #<Faraday::Response:0x00007fdd01ad1340
@on_complete_callbacks=[],
@env=#<Faraday::Env
@method=:get
@url=#<URI::HTTPS https://google.co.uk/>
@request=#<Faraday::RequestOptions (empty)>
@request_headers={"X-Version"=>"2", "User-Agent"=>"Faraday v1.7.1", "Authorization"=>"Token token"}
... Or another way is to add the
The main reason for that suggestion is that middleware usually provides greater functionality. faraday.request(:token_auth, 'token', {prop1: value1, prop2: value2})
# This produces `Authorization: Token token=token prop1=value1 prop2=value2 In a similar way, the I agree the I hope this answers your question, but in short you're good to use both methods, so use the one you like most 😄 |
@iMacTia Thank you so much for the help and detailed explanation!
It is super nice to know how to debug from now on. And by using that, you are fully correct:
Right, I put breakpoint in
Yes and thank you again! |
how to get rid of the deprecation warning for now though?
still raises the warning for me on 1.7.1 and, as @mscoutermarsh mentioned, the new syntax isn't available yet. |
Fixed it for us. Looks the same as yours, not sure why it's still giving you the warning. |
@paukul as @mscoutermarsh mentioned already, that line there is most probably not at fault for the warning you're seeing. The warning is only raised if you call the |
@mscoutermarsh @iMacTia you're right, we had another sneaky line of code I overlooked. Fixes it indeed. Thank you and sorry for the confusion |
No worries at all! Glad it worked and thanks for coming back and confirming 🙏 |
Question, so for basic I need:
but for Digest, I need:
Wouldn't it make sense to follow the same conventions for both? |
@rgaufman I'm not aware of a |
Just circling back on this, I believe the However, it has recently been brought to my attention that the gem only supports Faraday 0.x and 1.x. |
Basic Info
1.7.1
3.0.2
Issue description
Saw the deprecation warning, updated code to match the documented basic auth instructions. The documented code throws a number of arguments error.
Not sure if the docs are wrong or it's an issue with the gem.
Steps to reproduce
The text was updated successfully, but these errors were encountered: