Skip to content

Commit

Permalink
Merge 7de5dc8 into 83a97b7
Browse files Browse the repository at this point in the history
  • Loading branch information
iMacTia committed Aug 14, 2021
2 parents 83a97b7 + 7de5dc8 commit 3ef37ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Metrics/AbcSize:
# Offense count: 5
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 250
Max: 256

# Offense count: 15
# Configuration parameters: IgnoredMethods.
Expand Down
20 changes: 18 additions & 2 deletions docs/middleware/request/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ 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.

```ruby
Faraday.new(...) do |conn|
conn.basic_auth('username', 'password')
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.

```ruby
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.

```ruby
Faraday.new(...) do |conn|
conn.token_auth('authentication-token')
conn.request :authorization, 'Bearer', 'authentication-token'
end
```
15 changes: 15 additions & 0 deletions lib/faraday/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ def #{method}(url = nil, body = nil, headers = nil, &block)
#
# @return [void]
def basic_auth(login, pass)
warn <<~TEXT
WARNING: `Faraday::Connection#basic_auth` is deprecated; it will be removed in version 2.0.
While initializing your connection, use `#request(:basic_auth, ...)` instead.
See https://lostisland.github.io/faraday/middleware/authentication for more usage info.
TEXT
set_authorization_header(:basic_auth, login, pass)
end

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

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

Expand Down

0 comments on commit 3ef37ac

Please sign in to comment.