Skip to content

Commit fa612a0

Browse files
authored
[1.x] Deprecate Authorization helpers in Faraday::Connection (#1306)
1 parent 83a97b7 commit fa612a0

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Metrics/AbcSize:
1414
# Offense count: 5
1515
# Configuration parameters: CountComments, CountAsOne.
1616
Metrics/ClassLength:
17-
Max: 250
17+
Max: 256
1818

1919
# Offense count: 15
2020
# Configuration parameters: IgnoredMethods.

docs/middleware/request/authentication.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,38 @@ top_name: Back to Middleware
99
top_link: ./list
1010
---
1111

12-
Basic and Token authentication are handled by Faraday::Request::BasicAuthentication
13-
and Faraday::Request::TokenAuthentication respectively.
14-
These can be added as middleware manually or through the helper methods.
12+
The `Faraday::Request::Authorization` middleware allows you to automatically add an `Authorization` header
13+
to your requests. It also features 2 specialised sub-classes that provide useful extra features for Basic Authentication
14+
and Token Authentication requests.
15+
16+
### Any Authentication
17+
18+
The generic `Authorization` middleware allows you to add any type of Authorization header.
19+
20+
```ruby
21+
Faraday.new(...) do |conn|
22+
conn.request :authorization, 'Bearer', 'authentication-token'
23+
end
24+
```
1525

1626
### Basic Authentication
1727

28+
`BasicAuthentication` adds a 'Basic' type Authorization header to a Faraday request.
29+
1830
```ruby
1931
Faraday.new(...) do |conn|
20-
conn.basic_auth('username', 'password')
32+
conn.request :basic_auth, 'username', 'password'
2133
end
2234
```
2335

2436
### Token Authentication
2537

38+
`TokenAuthentication` adds a 'Token' type Authorization header to a Faraday request.
39+
You can optionally provide a hash of `options` that will be appended to the token.
40+
This is not used anymore in modern web and have been replaced by Bearer tokens.
41+
2642
```ruby
2743
Faraday.new(...) do |conn|
28-
conn.token_auth('authentication-token')
44+
conn.request :token_auth, 'authentication-token', **options
2945
end
3046
```

lib/faraday/connection.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ def #{method}(url = nil, body = nil, headers = nil, &block)
297297
#
298298
# @return [void]
299299
def basic_auth(login, pass)
300+
warn <<~TEXT
301+
WARNING: `Faraday::Connection#basic_auth` is deprecated; it will be removed in version 2.0.
302+
While initializing your connection, use `#request(:basic_auth, ...)` instead.
303+
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
304+
TEXT
300305
set_authorization_header(:basic_auth, login, pass)
301306
end
302307

@@ -314,6 +319,11 @@ def basic_auth(login, pass)
314319
#
315320
# @return [void]
316321
def token_auth(token, options = nil)
322+
warn <<~TEXT
323+
WARNING: `Faraday::Connection#token_auth` is deprecated; it will be removed in version 2.0.
324+
While initializing your connection, use `#request(:token_auth, ...)` instead.
325+
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
326+
TEXT
317327
set_authorization_header(:token_auth, token, options)
318328
end
319329

@@ -336,6 +346,11 @@ def token_auth(token, options = nil)
336346
#
337347
# @return [void]
338348
def authorization(type, token)
349+
warn <<~TEXT
350+
WARNING: `Faraday::Connection#authorization` is deprecated; it will be removed in version 2.0.
351+
While initializing your connection, use `#request(:authorization, ...)` instead.
352+
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
353+
TEXT
339354
set_authorization_header(:authorization, type, token)
340355
end
341356

0 commit comments

Comments
 (0)