Class: FaradayOauth2CcgMiddleware::ClientCredentialsGrant
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayOauth2CcgMiddleware::ClientCredentialsGrant
- Defined in:
- lib/faraday_oauth2_ccg_middleware.rb
Overview
Authorizes the request with the OAUTH2 Client Credentials Grant and injects the received token into the Authorization header
Faraday.new do |conn|
conn.request :oauth2_ccg,
oauth_host: 'https://server.example.com',
token_url: '/token',
client_id: 's6BhdRkqt3',
client_secret: '7Fjfp0ZBr1KtDRbnfVdmIw',
cache_store: ::ActiveSupport::Cache.lookup_store(:redis_store, 'redis://127.0.0.1:6379')
conn.adapter(:net_http) # NB: Last middleware must be the adapter
end
Defined Under Namespace
Classes: Options
Constant Summary collapse
- AUTHORIZATION_HEADER =
'Authorization'
- BEARER_AUTHORIZATION =
'Bearer'
- CLIENT_CREDENTIALS_GRANT =
'client_credentials'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = nil) ⇒ ClientCredentialsGrant
constructor
A new instance of ClientCredentialsGrant.
Constructor Details
#initialize(app, options = nil) ⇒ ClientCredentialsGrant
Returns a new instance of ClientCredentialsGrant.
66 67 68 69 |
# File 'lib/faraday_oauth2_ccg_middleware.rb', line 66 def initialize(app, = nil) super(app) @options = Options.from() end |
Instance Method Details
#call(env) ⇒ Object
72 73 74 75 76 |
# File 'lib/faraday_oauth2_ccg_middleware.rb', line 72 def call(env) env[:request_headers][AUTHORIZATION_HEADER] = "#{BEARER_AUTHORIZATION} #{token}" @app.call env end |