Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.22 KB

authentication.md

File metadata and controls

46 lines (36 loc) · 1.22 KB
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

Basic and Token authentication are handled by Faraday::Request::BasicAuthentication and Faraday::Request::TokenAuthentication respectively. These can be added as middleware manually or through the helper methods.

Basic Authentication

BasicAuthentication adds a 'Basic' type Authorization header to a Faraday request.

Faraday.new(...) do |conn|
  conn.request :basic_auth, 'username', 'password'
end

Token Authentication

TokenAuthentication adds a 'Token' type Authorization header to a Faraday request. You can optionally provide a hash of options that will be appended to the token. This is not used anymore in modern web and have been replaced by Bearer tokens.

Faraday.new(...) do |conn|
  conn.request :token_auth, 'authentication-token', **options
end

Custom Authentication

The generic Authorization middleware allows you to add any other type of Authorization header.

Faraday.new(...) do |conn|
  conn.request :authorization, 'Bearer', 'authentication-token'
end