1 # == Schema Information
3 # Table name: oauth_nonces
5 # id :bigint not null, primary key
13 # index_oauth_nonces_on_nonce_and_timestamp (nonce,timestamp) UNIQUE
16 # Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
17 # Thus you can use the same nonce with a different timestamp and viceversa.
18 class OauthNonce < ApplicationRecord
19 validates :timestamp, :presence => true
20 validates :nonce, :presence => true, :uniqueness => { :scope => :timestamp }
22 # Remembers a nonce and it's associated timestamp. It returns false if it has already been used
23 def self.remember(nonce, timestamp)
24 return false if Time.now.to_i - timestamp.to_i > 86400
26 oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp.to_i)
27 return false if oauth_nonce.new_record?