]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_nonce.rb
Revert "Switch to using oauth-plugin as a gem"
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / oauth_nonce.rb
diff --git a/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_nonce.rb b/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_nonce.rb
new file mode 100644 (file)
index 0000000..075351b
--- /dev/null
@@ -0,0 +1,13 @@
+# Simple store of nonces. The OAuth Spec requires that any given pair of nonce and timestamps are unique.
+# Thus you can use the same nonce with a different timestamp and viceversa.
+class OauthNonce < ActiveRecord::Base
+  validates_presence_of :nonce, :timestamp
+  validates_uniqueness_of :nonce, :scope => :timestamp
+  
+  # Remembers a nonce and it's associated timestamp. It returns false if it has already been used
+  def self.remember(nonce, timestamp)
+    oauth_nonce = OauthNonce.create(:nonce => nonce, :timestamp => timestamp)
+    return false if oauth_nonce.new_record?
+    oauth_nonce
+  end
+end