Class: JWTSignedRequest::Middlewares::Faraday

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/jwt_signed_request/middlewares/faraday.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, bearer_schema: nil, **options) ⇒ Faraday

Returns a new instance of Faraday.



9
10
11
12
13
14
# File 'lib/jwt_signed_request/middlewares/faraday.rb', line 9

def initialize(app, bearer_schema: nil, **options)
  @bearer_schema = bearer_schema
  @options = options

  initializer_args_requires_options? ? super(app, options) : super(app)
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jwt_signed_request/middlewares/faraday.rb', line 16

def call(env)
  env[:body] ||= ::JWTSignedRequest::EMPTY_BODY

  @jwt_token = ::JWTSignedRequest.sign(
    method:     env[:method],
    path:       env[:url].request_uri,
    headers:    env[:request_headers],
    body:       env[:body],
    **options,
  )

  env[:request_headers].store("Authorization", authorization_header)

  app.call(env)
end