]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/request_token.rb
Adding initial version of the OAuth token authentication method. This adds basic...
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / request_token.rb
diff --git a/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/request_token.rb b/vendor/plugins/oauth-plugin/generators/oauth_provider/templates/request_token.rb
new file mode 100644 (file)
index 0000000..b6047fe
--- /dev/null
@@ -0,0 +1,17 @@
+class RequestToken < OauthToken
+  def authorize!(user)
+    return false if authorized?
+    self.user = user
+    self.authorized_at = Time.now
+    self.save
+  end
+  
+  def exchange!
+    return false unless authorized?
+    RequestToken.transaction do
+      access_token = AccessToken.create(:user => user, :client_application => client_application)
+      invalidate!
+      access_token
+    end
+  end
+end
\ No newline at end of file