Class: Tinypass::AccessTokenStore

Inherits:
Object
  • Object
show all
Defined in:
lib/tinypass/token/access_token_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ AccessTokenStore

Returns a new instance of AccessTokenStore.



10
11
12
13
# File 'lib/tinypass/token/access_token_store.rb', line 10

def initialize(config = nil)
  @config = config
  @tokens = AccessTokenList.new
end

Instance Attribute Details

Returns the value of attribute raw_cookie.



8
9
10
# File 'lib/tinypass/token/access_token_store.rb', line 8

def raw_cookie
  @raw_cookie
end

#tokensObject (readonly)

Returns the value of attribute tokens.



8
9
10
# File 'lib/tinypass/token/access_token_store.rb', line 8

def tokens
  @tokens
end

Instance Method Details

#find_active_token(regexp) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/tinypass/token/access_token_store.rb', line 43

def find_active_token(regexp)
  tokens.each do |token|
    return token if token.rid =~ regexp && !token.expired?
  end

  nil
end

#get_access_token(rid) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tinypass/token/access_token_store.rb', line 24

def get_access_token(rid)
  rid = rid.to_s
  return tokens[rid] if tokens[rid]

  token = AccessToken.new(rid, -1)

  if tokens.size == 0
    token.access_state = AccessState::NO_TOKENS_FOUND
  else
    token.access_state = AccessState::RID_NOT_FOUND
  end

  return token
end

#has_token?(rid) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/tinypass/token/access_token_store.rb', line 39

def has_token?(rid)
  tokens.contains?(rid.to_s)
end


15
16
17
18
19
20
21
22
# File 'lib/tinypass/token/access_token_store.rb', line 15

def load_tokens_from_cookie(cookies, name = nil)
  name ||= Config.token_cookie_name(Tinypass.aid)
  @raw_cookie = cookies.respond_to?(:to_str) ? cookies : cookies[name]

  if @raw_cookie
    @tokens = ClientParser.new.parse_access_tokens(URI.unescape(raw_cookie))
  end
end