2 class ClientApplication < ActiveRecord::Base
4 has_many :tokens, :class_name => "OauthToken"
5 validates_presence_of :name, :url, :key, :secret
6 validates_uniqueness_of :key
7 before_validation_on_create :generate_keys
9 def self.find_token(token_key)
10 token = OauthToken.find_by_token(token_key, :include => :client_application)
11 if token && token.authorized?
12 logger.info "Loaded #{token.token} which was authorized by (user_id=#{token.user_id}) on the #{token.authorized_at}"
19 def self.verify_request(request, options = {}, &block)
21 signature = OAuth::Signature.build(request, options, &block)
22 logger.info "Signature Base String: #{signature.signature_base_string}"
23 logger.info "Consumer: #{signature.send :consumer_key}"
24 logger.info "Token: #{signature.send :token}"
25 return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
26 value = signature.verify
27 logger.info "Signature verification returned: #{value.to_s}"
29 rescue OAuth::Signature::UnknownSignatureMethod => e
30 logger.info "ERROR"+e.to_s
36 @oauth_server ||= OAuth::Server.new("http://your.site")
40 @oauth_client ||= OAuth::Consumer.new(key, secret)
43 def create_request_token
44 RequestToken.create :client_application => self
50 @oauth_client = oauth_server.generate_consumer_credentials
51 self.key = @oauth_client.key
52 self.secret = @oauth_client.secret