Class: Cpro::Middleware::Authentication

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/cpro/middleware/authentication.rb

Overview

Injecte les deux niveaux d'authentification Chorus Pro : le jeton OAuth2 PISTE, commun à l'application, et le compte technique cpro-account, porté par requête via le contexte Faraday puisqu'il peut changer d'un appel à l'autre.

Constant Summary collapse

ACCOUNT_HEADER =
"cpro-account"

Instance Method Summary collapse

Constructor Details

#initialize(app, token_provider:) ⇒ Authentication

Returns a new instance of Authentication.



11
12
13
14
# File 'lib/cpro/middleware/authentication.rb', line 11

def initialize(app, token_provider:)
  super(app)
  @token_provider = token_provider
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cpro/middleware/authentication.rb', line 16

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