1 class OauthToken < ActiveRecord::Base
2 belongs_to :client_application
4 validates_uniqueness_of :token
5 validates_presence_of :client_application, :token, :secret
6 before_validation :generate_keys, :on => :create
8 def self.find_token(token_key)
9 token = OauthToken.find_by_token(token_key, :include => :client_application)
10 if token && token.authorized?
11 logger.info "Loaded #{token.token} which was authorized by (user_id=#{token.user_id}) on the #{token.authorized_at}"
23 update_attribute(:invalidated_at, Time.now)
27 authorized_at != nil && !invalidated?
31 "oauth_token=#{token}&oauth_token_secret=#{secret}"
37 @oauth_token = client_application.oauth_server.generate_credentials
38 self.token = @oauth_token[0]
39 self.secret = @oauth_token[1]