generators/oauth_provider/templates/client_application.rb in oauth-plugin-0.3.14 vs generators/oauth_provider/templates/client_application.rb in oauth-plugin-0.4.0.pre1
- old
+ new
@@ -1,9 +1,12 @@
require 'oauth'
class ClientApplication < ActiveRecord::Base
belongs_to :user
has_many :tokens, :class_name => "OauthToken"
+ has_many :access_tokens
+ has_many :oauth2_verifiers
+ has_many :oauth_tokens
validates_presence_of :name, :url, :key, :secret
validates_uniqueness_of :key
before_validation_on_create :generate_keys
validates_format_of :url, :with => /\Ahttp(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
@@ -26,11 +29,10 @@
signature = OAuth::Signature.build(request, options, &block)
return false unless OauthNonce.remember(signature.request.nonce, signature.request.timestamp)
value = signature.verify
value
rescue OAuth::Signature::UnknownSignatureMethod => e
- logger.info "ERROR"+e.to_s
false
end
end
def oauth_server
@@ -39,17 +41,17 @@
def credentials
@oauth_client ||= OAuth::Consumer.new(key, secret)
end
- def create_request_token
- RequestToken.create :client_application => self,:callback_url=>self.token_callback_url
+ # If your application requires passing in extra parameters handle it here
+ def create_request_token(params={})
+ RequestToken.create :client_application => self, :callback_url=>self.token_callback_url
end
protected
def generate_keys
- oauth_client = oauth_server.generate_consumer_credentials
- self.key = oauth_client.key[0,20]
- self.secret = oauth_client.secret[0,40]
+ self.key = OAuth::Helper.generate_key(40)[0,40]
+ self.secret = OAuth::Helper.generate_key(40)[0,40]
end
end