class Razoul::Token

Attributes

created_at[RW]
value[RW]

Public Class Methods

current_token() click to toggle source
# File lib/razoul/token.rb, line 24
def current_token
  Marshal.load(persistence.find(Razoul.configuration.token_key))
end
generate!() click to toggle source
# File lib/razoul/token.rb, line 28
def generate!
  persistence.save(Razoul.configuration.token_key, Marshal.dump(new))
end
new() click to toggle source
# File lib/razoul/token.rb, line 6
def initialize
  @value = self.generate_key
  @created_at = Time.now.to_i
end
valid_token?(token) click to toggle source
# File lib/razoul/token.rb, line 32
def valid_token?(token)
  token.eql?(Marshal.load(persistence.find(Razoul.configuration.token_key)).value) ? true : false
end

Public Instance Methods

expired?() click to toggle source
# File lib/razoul/token.rb, line 18
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() click to toggle source
# File lib/razoul/token.rb, line 11
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