class WCC::Data::RackClientAppTokenAuth
Attributes
app[R]
cache[R]
lookup_token[R]
Public Class Methods
new(app, cache: default_cache, lookup_token: method(:default_lookup_token))
click to toggle source
# File lib/wcc/data/rack_client_app_token_auth.rb, line 37 def initialize(app, cache: default_cache, lookup_token: method(:default_lookup_token)) @app = app @cache = cache @lookup_token = lookup_token end
Public Instance Methods
call(env)
click to toggle source
# File lib/wcc/data/rack_client_app_token_auth.rb, line 54 def call(env) _, token_string = env["HTTP_AUTHORIZATION"].split(/\s+/) if find(token_string) app.call(env) else [403, {}, ['{"error":"Invalid Bearer Token"}']] end end
find(token)
click to toggle source
# File lib/wcc/data/rack_client_app_token_auth.rb, line 43 def find(token) cached = cache.find(token) return cached if cached val = lookup_token.(token) cache << token if val val end
Private Instance Methods
default_cache()
click to toggle source
# File lib/wcc/data/rack_client_app_token_auth.rb, line 65 def default_cache RedisCache.new(Sidekiq.method(:redis)) end
default_lookup_token(token)
click to toggle source
# File lib/wcc/data/rack_client_app_token_auth.rb, line 69 def default_lookup_token(token) WCC::Data::Nucleus::ClientAppToken.find(token) rescue WCC::Data::Mapper::InvalidResponse, WCC::Data::Mapper::RecordNotFound nil end