faraday/docs/middleware/request/authentication.md
Matt fe600c72ad
Drop deprecated auth helpers from Connection. (#1308)
Merge Authentication middleware.
Add possibility of passing a proc.
Update documentation.
2021-08-15 10:28:49 +02:00

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