Class: RippleToken::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
# File 'lib/ripple_token/middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#_call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ripple_token/middleware.rb', line 13

def _call(env)
  method = env['REQUEST_METHOD']
  path = env['PATH_INFO']

  encoded_token = env['HTTP_AUTHORIZATION']&.gsub(/^Bearer /, '') || ''

  Client.logger.debug("Received #{encoded_token} token")

  if encoded_token.nil? || encoded_token&.empty?
    Client.logger.info('No token provided in request')
    raise MissingTokenError unless token.public_path? method, path
  else
    store_user_details(encoded_token, env)
  end

  @app.call(env)
end

#call(env) ⇒ Object



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

def call(env)
  dup._call env
end