Class: Hadley::TokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/hadley/token_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ TokenStore

Returns a new instance of TokenStore.



3
4
5
# File 'lib/hadley/token_store.rb', line 3

def initialize(store)
  @store = store
end

Instance Method Details

#delete(token) ⇒ Object



23
24
25
# File 'lib/hadley/token_store.rb', line 23

def delete(token)
  @store.delete(key_for(token))
end

#get(token) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/hadley/token_store.rb', line 11

def get(token)
  access = @store.read(key_for(token))
  if access
    access[:anonymous] = access[:identity] == Hadley::ANONYMOUS_IDENTITY
  end
  access
end

#key_for(token) ⇒ Object



7
8
9
# File 'lib/hadley/token_store.rb', line 7

def key_for(token)
  "afid-access-token:#{token}"
end

#put(token, expires_in, data = {}) ⇒ Object



19
20
21
# File 'lib/hadley/token_store.rb', line 19

def put(token, expires_in, data={})
  @store.write(key_for(token), data, expires_in: expires_in)
end