Class: Cpro::Middleware::Authentication
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Cpro::Middleware::Authentication
- Defined in:
- lib/cpro/middleware/authentication.rb
Overview
Porte le jeton OAuth2 PISTE, commun à l'application, et rejoue une fois l'appel refusé en 401. Le compte technique, lui, est posé par Resources::Base : il change d'un appel à l'autre et Faraday n'offre pas de contexte de requête avant la 1.0.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, token_provider:) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(app, token_provider:) ⇒ Authentication
Returns a new instance of Authentication.
9 10 11 12 |
# File 'lib/cpro/middleware/authentication.rb', line 9 def initialize(app, token_provider:) super(app) @token_provider = token_provider end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cpro/middleware/authentication.rb', line 14 def call(env) body = env.body retried = false begin reset(env, body) apply(env) @app.call(env) rescue AuthenticationError raise if retried retried = true @token_provider.invalidate! retry end end |