Sha256: 87188e63849d523c5afa6a64a64056daf8d4158eae4e69f4244089f97b46b580
Contents?: true
Size: 780 Bytes
Versions: 1
Compression:
Stored size: 780 Bytes
Contents
module Touth module ActsAsTokenAuthenticatable def access_token(lifetime = Touth.access_token_lifetime) expires_at = Time.now.to_i + lifetime "#{access_token_id(expires_at)}#{[expires_at].pack('V')}".unpack('H*')[0] end def valid_access_token?(token) begin data = [token].pack 'H*' token_id, timestamp = data[0..0x1f], data[0x20..-1] expires_at = timestamp.unpack('V')[0] access_token_id(expires_at) == token_id && Time.now.to_i < expires_at rescue false end end private def access_token_id(expires_at) raw = [ expires_at, self.class.name, self.id, self.send(Touth.password_field), ].join ':' Touth.digest raw end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
touth-1.0.0 | lib/touth/acts_as_token_authenticatable.rb |