Class: WCC::Data::RackClientAppTokenAuth
- Inherits:
-
Object
- Object
- WCC::Data::RackClientAppTokenAuth
- Defined in:
- lib/wcc/data/rack_client_app_token_auth.rb
Defined Under Namespace
Classes: RedisCache
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#lookup_token ⇒ Object
readonly
Returns the value of attribute lookup_token.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #find(token) ⇒ Object
-
#initialize(app, cache: default_cache, lookup_token: method(:default_lookup_token)) ⇒ RackClientAppTokenAuth
constructor
A new instance of RackClientAppTokenAuth.
Constructor Details
#initialize(app, cache: default_cache, lookup_token: method(:default_lookup_token)) ⇒ RackClientAppTokenAuth
Returns a new instance of RackClientAppTokenAuth.
37 38 39 40 41 |
# 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 |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
35 36 37 |
# File 'lib/wcc/data/rack_client_app_token_auth.rb', line 35 def app @app end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
35 36 37 |
# File 'lib/wcc/data/rack_client_app_token_auth.rb', line 35 def cache @cache end |
#lookup_token ⇒ Object (readonly)
Returns the value of attribute lookup_token.
35 36 37 |
# File 'lib/wcc/data/rack_client_app_token_auth.rb', line 35 def lookup_token @lookup_token end |
Instance Method Details
#call(env) ⇒ Object
54 55 56 57 58 59 60 61 |
# 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) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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 |