]> git.openstreetmap.org Git - rails.git/blob - vendor/plugins/oauth-plugin/generators/oauth_provider/templates/oauth_token.rb
Add a link to [[Visibility of GPS traces]] on the wiki to explain what public/private...
[rails.git] / vendor / plugins / oauth-plugin / generators / oauth_provider / templates / oauth_token.rb
1 class OauthToken < ActiveRecord::Base
2   belongs_to :client_application
3   belongs_to :user
4   validates_uniqueness_of :token
5   validates_presence_of :client_application, :token, :secret
6   before_validation_on_create :generate_keys
7   
8   def invalidated?
9     invalidated_at != nil
10   end
11   
12   def invalidate!
13     update_attribute(:invalidated_at, Time.now)
14   end
15   
16   def authorized?
17     authorized_at != nil && !invalidated?
18   end
19   
20   def to_query
21     "oauth_token=#{token}&oauth_token_secret=#{secret}"
22   end
23     
24 protected
25   
26   def generate_keys
27     @oauth_token = client_application.oauth_server.generate_credentials
28     self.token = @oauth_token[0]
29     self.secret = @oauth_token[1]
30   end
31 end