1 require 'oauth/signature'
5 module ControllerMethods
12 def current_client_application
13 @current_client_application
17 logger.info "entering oauthenticate"
18 verified=verify_oauth_signature
19 logger.info "verified=#{verified.to_s}"
20 return verified && current_token.is_a?(::AccessToken)
27 # use in a before_filter
29 logger.info "Current_token=#{@current_token.inspect}"
31 logger.info "passed oauthenticate"
33 logger.info "passed authorized"
36 logger.info "failed authorized"
37 invalid_oauth_response
40 logger.info "failed oauthenticate"
42 invalid_oauth_response
46 # This requies that you have an acts_as_authenticated compatible authentication plugin installed
47 def login_or_oauth_required
52 invalid_oauth_response
60 # verifies a request token request
61 def verify_oauth_consumer_signature
63 valid = ClientApplication.verify_request(request) do |token, consumer_key|
64 @current_client_application = ClientApplication.find_by_key(consumer_key)
66 # return the token secret and the consumer secret
67 [nil, @current_client_application.secret]
73 invalid_oauth_response unless valid
76 def verify_oauth_request_token
77 verify_oauth_signature && current_token.is_a?(RequestToken)
80 def invalid_oauth_response(code=401,message="Invalid OAuth Request")
81 render :text => message, :status => code
86 def current_token=(token)
89 @current_user=@current_token.user
90 @current_client_application=@current_token.client_application
95 # Implement this for your own application using app-specific models
96 def verify_oauth_signature
98 valid = ClientApplication.verify_request(request) do |request|
99 self.current_token = ClientApplication.find_token(request.token)
100 logger.info "self=#{self.class.to_s}"
101 logger.info "token=#{self.current_token}"
102 # return the token secret and the consumer secret
103 [(current_token.nil? ? nil : current_token.secret), (current_client_application.nil? ? nil : current_client_application.secret)]
105 # reset @current_user to clear state for restful_...._authentication
106 @current_user = nil if (!valid)