mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Merge Authentication middleware. Add possibility of passing a proc. Update documentation.
937 B
937 B
layout | title | permalink | hide | next_name | next_link | top_name | top_link |
---|---|---|---|---|---|---|---|
documentation | Authentication Middleware | /middleware/authentication | true | Multipart Middleware | ./multipart | Back to Middleware | ./list |
The Faraday::Request::Authorization
middleware allows you to automatically add an Authorization
header
to your requests. It also features a handy helper to manage Basic authentication.
Faraday.new(...) do |conn|
conn.request :authorization, 'Bearer', 'authentication-token'
end
With a proc
You can also provide a proc, which will be evaluated on each request:
Faraday.new(...) do |conn|
conn.request :authorization, 'Bearer', -> { MyAuthStorage.get_auth_token }
end
Basic Authentication
The middleware will automatically Base64 encode your Basic username and password:
Faraday.new(...) do |conn|
conn.request :authorization, :basic, 'username', 'password'
end