From afa10df037ad835489def5f827a5d3e5cd4de330 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Sep 2021 09:48:56 +0100 Subject: [PATCH] Add Faraday 1.x examples in authentication.md docs Fixes #1317 Fixes #1314 --- docs/middleware/request/authentication.md | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/middleware/request/authentication.md b/docs/middleware/request/authentication.md index 70da6e317..4dc5ab486 100644 --- a/docs/middleware/request/authentication.md +++ b/docs/middleware/request/authentication.md @@ -11,6 +11,8 @@ top_link: ./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. +**Please note the way you use this middleware in Faraday 1.x is different**, +examples are available at the bottom of this page. ```ruby Faraday.new(...) do |conn| @@ -37,3 +39,28 @@ Faraday.new(...) do |conn| conn.request :authorization, :basic, 'username', 'password' end ``` + +### Faraday 1.x usage + +In Faraday 1.x, the way you use this middleware is slightly different: + +```ruby +# Basic Auth request +# Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ= +Faraday.new(...) do |conn| + conn.request :basic_auth, 'username', 'password' +end + +# Token Auth request +# `options` are automatically converted into `key=value` format +# Authorization: Token authentication-token +Faraday.new(...) do |conn| + conn.request :token_auth, 'authentication-token', **options +end + +# Generic Auth Request +# Authorization: Bearer authentication-token +Faraday.new(...) do |conn| + conn.request :authorization, 'Bearer', 'authentication-token' +end +```