Class: Razoul::Token
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #expired? ⇒ Boolean
- #generate_key ⇒ Object
-
#initialize ⇒ Token
constructor
A new instance of Token.
Methods inherited from Model
Constructor Details
#initialize ⇒ Token
Returns a new instance of Token.
7 8 9 10 |
# File 'lib/razoul/token.rb', line 7 def initialize @value = self.generate_key @created_at = Time.now.to_i end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
4 5 6 |
# File 'lib/razoul/token.rb', line 4 def created_at @created_at end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/razoul/token.rb', line 4 def value @value end |
Class Method Details
.current_token ⇒ Object
25 26 27 |
# File 'lib/razoul/token.rb', line 25 def current_token Marshal.load(persistence.find(Razoul.configuration.token_key)) end |
.generate! ⇒ Object
29 30 31 |
# File 'lib/razoul/token.rb', line 29 def generate! persistence.save(Razoul.configuration.token_key, Marshal.dump(new)) end |
.valid_token?(token) ⇒ Boolean
33 34 35 |
# File 'lib/razoul/token.rb', line 33 def valid_token?(token) token.eql?(Marshal.load(persistence.find(Razoul.configuration.token_key)).value) ? true : false end |
Instance Method Details
#expired? ⇒ Boolean
19 20 21 22 |
# File 'lib/razoul/token.rb', line 19 def expired? puts "Time now: #{Time.now.to_i} - #{self.created_at}" Time.now.to_i - self.created_at >= Razoul.configuration.expiration_time end |
#generate_key ⇒ Object
12 13 14 15 16 17 |
# File 'lib/razoul/token.rb', line 12 def generate_key digest = OpenSSL::Digest::SHA256.new secret = Razoul.configuration.password string = Razoul.configuration.login + Time.now.to_s OpenSSL::HMAC.hexdigest(digest, secret, string) end |