Class: Hadley::TokenStore
- Inherits:
-
Object
- Object
- Hadley::TokenStore
- Defined in:
- lib/hadley/token_store.rb
Overview
This class handles the storage, retrieval and removal of OAuth 2 bearer tokens sent from the AFID authorization server. The TokenStore delegates most of the work to the delegate store, which must support the api set forth by ActiveSupport::Cache::Store.
Instance Method Summary collapse
-
#delete(token) ⇒ Boolean?
This method removes the AFID identity information associated with the provided token.
-
#get(token) ⇒ Hash?
This method retrieves the AFID identity information associated with the provided token.
-
#initialize(store) ⇒ TokenStore
constructor
This method initializes the TokenStore with the delegate store.
-
#key_for(token) ⇒ Symbol
protected
This method derives the appropriate datastore key from the given AFID token.
-
#put(token, expires_in, data = {}) ⇒ Boolean?
This method stores the provided AFID identity information under the given AFID token for the duration of time specified by the expires_in argument.
Constructor Details
#initialize(store) ⇒ TokenStore
This method initializes the TokenStore with the delegate store.
10 11 12 |
# File 'lib/hadley/token_store.rb', line 10 def initialize(store) @store = store end |
Instance Method Details
#delete(token) ⇒ Boolean?
This method removes the AFID identity information associated with the provided token.
47 48 49 |
# File 'lib/hadley/token_store.rb', line 47 def delete(token) @store.delete(key_for(token)) end |
#get(token) ⇒ Hash?
This method retrieves the AFID identity information associated with the provided token. If no such identity is found the result will be nil.
21 22 23 24 25 26 27 |
# File 'lib/hadley/token_store.rb', line 21 def get(token) access = @store.read(key_for(token)) if access access[:anonymous] = access[:identity] == Hadley::ANONYMOUS_IDENTITY end access end |
#key_for(token) ⇒ Symbol (protected)
This method derives the appropriate datastore key from the given AFID token.
58 59 60 |
# File 'lib/hadley/token_store.rb', line 58 def key_for(token) "afid-access-token:#{token}".to_sym end |
#put(token, expires_in, data = {}) ⇒ Boolean?
This method stores the provided AFID identity information under the given AFID token for the duration of time specified by the expires_in argument.
38 39 40 |
# File 'lib/hadley/token_store.rb', line 38 def put(token, expires_in, data={}) @store.write(key_for(token), data, expires_in: expires_in) end |