-
Notifications
You must be signed in to change notification settings - Fork 203
Oauth
Mattia edited this page Aug 3, 2017
·
1 revision
Available middleware:
- FaradayMiddleware::OAuth
- FaradayMiddleware::OAuth2
Example use (OAuth 2):
## in Faraday 0.8 or above:
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
:
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.
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.
(Please note: This wiki has been closed, and turned into in-repo Markdown
documents. You can find them in the repository's docs/
directory. This wiki does not take new edits.)