1 class OauthToken < ActiveRecord::Base
2 belongs_to :client_application
5 scope :authorized, where("authorized_at IS NOT NULL and invalidated_at IS NULL")
7 validates_uniqueness_of :token
8 validates_presence_of :client_application, :token, :secret
10 before_validation :generate_keys, :on => :create
12 def self.find_token(token_key)
13 token = OauthToken.find_by_token(token_key, :include => :client_application)
14 if token && token.authorized?
15 logger.info "Loaded #{token.token} which was authorized by (user_id=#{token.user_id}) on the #{token.authorized_at}"
27 update_attribute(:invalidated_at, Time.now)
31 authorized_at != nil && !invalidated?
35 "oauth_token=#{token}&oauth_token_secret=#{secret}"
41 @oauth_token = client_application.oauth_server.generate_credentials
42 self.token = @oauth_token[0]
43 self.secret = @oauth_token[1]