Class: Drillbit::Middleware::TokenProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/drillbit/middleware/token_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TokenProcessor

Returns a new instance of TokenProcessor.



9
10
11
# File 'lib/drillbit/middleware/token_processor.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/drillbit/middleware/token_processor.rb', line 13

def call(env)
  request = Requests::Base.resolve(env)
  token   = request.authorization_token

  return Responses::InvalidToken.call(env, application_name: request.application_name) \
         unless token.valid?

  env['X_JSON_WEB_TOKEN'] = token.to_h

  @app.call(env)
end