File: oauth.md

package info (click to toggle)
ruby-faraday-middleware 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 376 kB
  • sloc: ruby: 2,388; sh: 15; makefile: 6
file content (32 lines) | stat: -rw-r--r-- 977 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# OAuth Middleware for token authentication

Available middleware:

* FaradayMiddleware::OAuth
* FaradayMiddleware::OAuth2

Example use (OAuth 2):

```rb
connection = Faraday.new('http://example.com/api') do |conn|
  conn.request :oauth2, 'token'
  conn.adapter Faraday.default_adapter
end
```

This will cause the 'token' to be inserted in both the query params (as `access_token`) and headers (as `Token token=<token_value>`).

As of FaradayMiddleware 0.11, you can specify the `token_type` option as `:bearer`:

```rb
connection = Faraday.new('http://example.com/api') do |conn|
  conn.request :oauth2, 'token', token_type: :bearer
  conn.adapter Faraday.default_adapter
end
```

This will cause the token to be inserted ONLY as a header (as `Bearer <token_value>`), which is more standard-compliant.

## DEPRECATION WARNING

Inserting the token as a parameter is now considered a security issue, therefore the next major release of Faraday will only add tokens on headers.